daemon-php Daemon has been running for some time, but it's not working.

Source: Internet
Author: User
Tags php cli
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.