我的PHP While(true)自动在cpanel中停止 [英] My PHP While(true) automatically stopped in cpanel
本文介绍了我的PHP While(true)自动在cpanel中停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在本地主机上测试了该脚本一整天,并且仍在运行。但是在cpanel中,该脚本会自动停止
I have tested this script in my localhost a whole day and it's still working. But in cpanel this script is stopped automatically
set_time_limit(0);
ini_set('memory_limit', '-1');
$run = TRUE;
$nowtime = date("Y-m-d H:i");
while($run){
$stop = GetSetting("Stop");
$time = date("Y-m-d H:i");
if($stop){
$run = FALSE; // stopped when setting changed
continue;
}
if($time != $nowtime){
log_message("debug","Still Running On ".$time); //checking if it still running every minute
}
$nowtime = $time;
}
您认为发生了什么?有什么可能的情况使它停止?与记忆有关吗?或服务器配置?还是有其他可能性?
what do you think happened? What is possible cases that made it stop? Is it about memory? or server configuration? or other possibility?
推荐答案
您可以通过从命令行运行PHP来非常容易地做到这一点。这是一个示例脚本,用于显示概念验证。我在Windows XP上运行PHP 5.3.18(oi !,停止laffin')。
You can do this very easily by running PHP from the 'command line'. Here is a sample script to show 'proof of concept'. I run PHP 5.3.18 on windows XP (oi!, stop laffin').
我显示捕获的输出。
脚本:
<?php
// P:\developer\xampp\htdocs\testmysql\Q22710846.php
//
// run this from the command line - press ctrl-c to kill the task.
set_time_limit(0);
$run = TRUE;
$nowtime = date("Y-m-d H:i:s");
$debug = false; // set true to stop after 10
$loopCount = 10;
if (!$debug) {
echo "press ctrl-c to end the task as it will forever!\n\n";
}
while(($debug && $loopCount) || (!$debug && $run)) { // will run forever...
$nowtime = date("Y-m-d H:i:s");
echo 'The time now is, beep, beep, beep : ', $nowtime, "\n";
// generate a random delay of between 1 and 10 seconds
$delay = mt_rand(1, 10);
echo 'waiting for : ', $delay, " seconds\n";
sleep($delay);
// log_message("debug","Still Running On ".$time); //checking if it still running every minute
if ($debug) {
$loopCount--;
}
}
?>
样本输出...
P:\developer\xampp\htdocs\testmysql>php Q22710846.php
press ctrl-c to end the task as it will forever!
The time now is, beep, beep, beep : 2014-04-02 11:19:03
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:11
waiting for : 7 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:18
waiting for : 6 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:24
waiting for : 6 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:30
waiting for : 5 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:35
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:43
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:51
waiting for : 2 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:53
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:01
waiting for : 1 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:02
waiting for : 3 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:05
waiting for : 7 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:12
waiting for : 9 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:21
waiting for : 9 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:30
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:38
waiting for : 1 seconds
^C
P:\developer\xampp\htdocs\testmysql>
这篇关于我的PHP While(true)自动在cpanel中停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文