Home >Backend Development >PHP Tutorial >PHP online update solution
The current demand scenario is as follows:
I develop an extension that runs on various open source cms systems, such as wordpress, discuz, etc.
Now if a user installs and uses our product, we will issue a new version and prompt the user to update. The user clicks a button and is instantly upgraded to the new version. Users expressed satisfaction.
The users are satisfied, but to complete this action here, we must develop an automatic upgrade system for each open source cms. I have developed this system before. It is quite troublesome to compare versions, download files, etc. A single cms is fine, but in the future it will be expanded to many cms. We have to develop this thing for this set of cms, which is a lot of work. It's huge. Therefore, I now hope to develop a common mechanism that can be applied to all CMS systems. Is there any good method?
——————————————————————————————————————
I now have an idea. First of all, the difficulty in implementing this function is that it is impossible for a php file to replace itself. That is to say, it is impossible for this running php file to delete itself or modify its own source code.
So, there must be a file that plays the role of modifying others. His own things don't change, and his existence is to change others.
For example, there are three files a, b, and c under this extension. When the user clicks to upgrade, an ajax request is sent to directly access and run the c file. The c file runs independently and does not depend on other files. In this way, he can modify, delete, etc. files a and b, thus achieving the purpose of automatic updating. For all cms extensions, I only need to put a file c under each directory, and that will be fine. This Has the workload been reduced exponentially?
Is this solution feasible?
The current demand scenario is as follows:
I develop an extension that runs on various open source cms systems, such as wordpress, discuz, etc.
Now if a user installs and uses our product, we will issue a new version and prompt the user to update. The user clicks a button and is instantly upgraded to the new version. Users expressed satisfaction.
The users are satisfied, but to complete this action here, we must develop an automatic upgrade system for each open source cms. I have developed this system. It is quite troublesome to compare versions, download files, etc. A single cms is fine, but in the future it will be expanded to many cms. We have to develop this thing for this set of cms, so the workload It's huge. Therefore, I now hope to develop a common mechanism that can be applied to all CMS systems. Is there any good method?
——————————————————————————————————————
I now have an idea. First of all, the difficulty in implementing this function is that it is impossible for a php file to replace itself. That is to say, it is impossible for this running php file to delete itself or modify its own source code.
So, there must be a file that plays the role of modifying others. His own things don't change, and his existence is to change others.
For example, there are three files a, b, and c under this extension. When the user clicks to upgrade, an ajax request is sent to directly access and run the c file. The c file runs independently and does not depend on other files. In this way, he can modify, delete, etc. files a and b, thus achieving the purpose of automatic updating. For all cms extensions, I only need to put a file c under each directory, and that will be fine. This Has the workload been reduced exponentially?
Is this solution feasible?
I thought of a general idea:
First of all, it is recommended to divide it into major version updates and patch updates. If the major version update is more complicated, you still have to download the file and overwrite the file manually.
Small version update can build a general update deployment method:
The client uniformly updates the request to the central server-side interface or entry file for processing updates. Through the entry file, an upgrade package is dynamically generated based on the local environment series data submitted by the client. As well as the deployed JSON configuration file, the client reads the JSON after receiving it and then upgrades the database, replaces files, etc. In this way, the server only needs to continuously maintain various CMS upgrade rules after version upgrades.
Having said that, the workload is still huge!
composer
!composer
!composer
!!!!!!!!!!
My thinking is really rigid.
Since PHP cannot change itself, then change the configuration file or the database, and the problem will be solved.