开发者

Is there a way to kill a PHP program while it's working?

Is there a way to kill a PHP program while it's working? I know in Linux/Unix I can do

ps -u [username]

And it will tell me what processes are running. To stop a process I just enter

kill [process #]

With PHP is there any way to see what processes are currently runnin开发者_运维技巧g on the remote server and kill an individual program from completion? Ideally using exec()?

The reason that I ask is that I am on a shared hosting environment and I work on & test my programs directly on the server... Every now and then I'll do something silly like enter a ridiculous number of loops, accidentally, where it can take several minutes to an hour to actually complete.

Seeing that there is virtually no information on the subject, I thought it would be an interesting question to throw out there.

Thanks!


Ask your hosting provider for SSH access and do that in Unix way. Still you can emulate shell access with a system function and friends:

exec("ps --no-header -eo pid,user,comm", $output);
foreach ($output as $line) {
    $line = preg_split('#\s+#', trim($line));
    echo "PID: $line[0] USER: $line[1] PRG: $line[2]\n";
}

Disclaimer: you probably won't be able to kill Apache processes even if you will have shell access.


if u have some infinite loop or something, put this

    while(1){

    if(!file_exists("continue.txt")){
    die("Stop");
    }

//Your Code here.

    }

so when u delete that file "continue.txt", your script dies.


You can change set_time_limt settings before the risk of a loop, making the script stop after 10 seconds if you wish.

http://php.net/manual/en/function.set-time-limit.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜