I ran a daemon in the background with while (true), the task of the process was to read the interface and put the interface contents into MySQL && Redis && json.js.
The problem is that the process is running for a period of time (about half a month), not dead, but not working.
Excuse me, is this a common question? Or is there a problem with my code that is causing the problem.
My solution now is to restart the process on a regular basis, is there a better way?
Part of the Code
public function sync() { while(true){ $this->syncData(); sleep(5); }}
Reply content:
I ran a daemon in the background with while (true), the task of the process was to read the interface and put the interface contents into MySQL && Redis && json.js.
The problem is that the process is running for a period of time (about half a month), not dead, but not working.
Excuse me, is this a common question? Or is there a problem with my code that is causing the problem.
My solution now is to restart the process on a regular basis, is there a better way?
Part of the Code
public function sync() { while(true){ $this->syncData(); sleep(5); }}
When writing a PHP CLI program running at the command line, it is recommended that you do not use persistent connections, and it is recommended that you reopen and close the database connection every time you use MySQL, preventing the CLI program from failing when the database connection is lost. Redis is the same.
Think you can try Workerman or swoole the two frameworks that are suitable for daemon tasks, both of which are more active and users are more
Use the while in the shell instead of PHP while