I used while (true) to run a daemon in the background. The task of the process is to read the interface and put the interface content into Mysql & amp; redis & amp; json. js. The problem is that after the process runs for a period of time (about half a month), it does not die, but does not work. This is a regular... I used while (true) to run a daemon in the background. The task of the process is to read the interface and put the interface content into Mysql & Redis & json. js.
The problem is that after the process runs for a period of time (about half a month), it does not die, but does not work.
Is this a common problem? It is also caused by a problem with my code.
My current solution is to regularly restart the process. Is there a better solution?
Some code
public function sync() { while(true){ $this->syncData(); sleep(5); }}
Reply content:
I used while (true) to run a daemon in the background. The task of the process is to read the interface and put the interface content into Mysql & Redis & json. js.
The problem is that after the process runs for a period of time (about half a month), it does not die, but does not work.
Is this a common problem? It is also caused by a problem with my code.
My current solution is to regularly restart the process. Is there a better solution?
Some code
public function sync() { while(true){ $this->syncData(); sleep(5); }}
We recommend that you do not use persistent connections when writing a php cli program running in the command line. We recommend that you re-open and close the database connection every time you use MySQL, avoid CLI program failure when database connection is lost. redis is the same.
The workerman or swoole framework is suitable for daemon tasks. Both are active and there are many users.
Use shell's while to replace PHP's while