[100 points] PHP daemon "Stuck" all processes? What to do with it

Source: Internet
Author: User
[100 points] PHP daemon "Stuck" all processes?
Rookie one, need to write a guardian process. I checked the information, and I wrote two lines of tests.

Ignore user Disconnects
Ignore_user_abort (TRUE);
Ignore timeout time
Set_time_limit (0);
while (true)
{
$logContent = Date (' y-m-d h:i:s '). " \ r \ n ";
File_put_contents (' Log.txt ', $logContent, file_append);

Sleep (10);
}


This thing is every 10 seconds, the old log file to write down the current time. But as soon as this thing was executed, the whole Apache was found to be unresponsive. For example, this writing in the a.php, the other b.php what all the files are useless. Apache seems to be stuck in the same way. Want to know what this is about?



------Solution--------------------
Just the few lines of code that you have, you're not going to get the symptoms.
------Solution--------------------
#vi log.php
$logContent = Date (' y-m-d h:i:s '). " \ r \ n ";
File_put_contents (' Log.txt ', $logContent, file_append);
?>

#crontab-E

*/10 * * * */usr/local/php/bin/php log.php

-------------------------------------------------------

PHP File Write absolute path
------Solution--------------------
Windows

>notepad Log.bat

#{your-php-bin-path}php log.php

>SCHTASKS/CREATE/SC minute/mo 10/tn "Php-date-log"/tr log.bat
------Solution--------------------
The server restricts the possibility of a single process
Change a browser Firefox open a Google open b
Do not use the IE kernel browser ...
------Solution--------------------
That is not the problem. You can try to change the time to a little longer.
Also, to give a suggestion, PHP want to implement timed execution, Windows can use scheduled Tasks, Linux can use cron, you use this is not recommended. And, you do this, when the computer restarts or the Apache restarts after the invalid, you need to run the code again to continue to execute.
  • 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.