Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP在不活动后终止进程_Php - Fatal编程技术网

PHP在不活动后终止进程

PHP在不活动后终止进程,php,Php,我有一个脚本,它可能在一段时间后不会变为非活动状态,因为它从一个非常慢的服务器请求信息,会话过期时间很短。 脚本echos在其每个进程完成后都会进入shell,这是我调试代码的方式。有没有办法从另一个脚本执行该脚本,并在上一次echo一段时间后将其终止。换句话说,在不活动后终止脚本。 编辑:这里我们可以使用我的代码示例: foreach ($info["Ten_Friends"] as $friend) { $info = []; echo "11111 \n"; $in

我有一个脚本,它可能在一段时间后不会变为非活动状态,因为它从一个非常慢的服务器请求信息,会话过期时间很短。
脚本
echo
s在其每个进程完成后都会进入shell,这是我调试代码的方式。有没有办法从另一个脚本执行该脚本,并在上一次
echo
一段时间后将其终止。换句话说,在不活动后终止脚本。
编辑:这里我们可以使用我的代码示例:

foreach ($info["Ten_Friends"] as $friend) {
    $info = [];
    echo "11111 \n";
    $info = $i->userAnalysis($friend);
    if ($info != false) {
        echo "if to database\n";
        if (($i->usersDatabase($info) == true)) {
            mediaDataBase($info);
            $nAnalized += 1;
            echo "nAnalized: ".$nAnalized."\n";
        }
    } else {echo $friend." not analised";}

    echo "3333\n";
}
正如您所看到的,在每个进程之后,我都会回显。都是
$i->userAnalysis($friend)
$i->usersDatabase($info)
向服务器请求数据此函数在一段时间后可能会失去响应,因此如果它们这样做,我需要终止脚本。
在Osx El Capitan和mysql上运行Php 5.6

$cmd = "php AnalyzeFriends.php";
$timeout_tolerance = 10; // 10 seconds
$last_response = time(); // start time

ob_implicit_flush(true);
ob_end_flush();

$descriptorspec = array(
   0 => array("pipe", "r"),   // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),   // stdout is a pipe that the child will write to
   2 => array("pipe", "w")    // stderr is a pipe that the child will write to
);
flush();
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo "<pre>";
if (is_resource($process)) {
    while ($s = fgets($pipes[1])) {
        print $s;
        if((time() - $last_response) > $timeout_tolerance){
          fclose($pipes[0]);
          fclose($pipes[1]);
          fclose($pipes[2]);
          proc_close($process);
        }
        $last_response = time();
        flush();
    }
}
echo "</pre>";
$cmd=“php AnalyzeFriends.php”;
$timeout\u公差=10;//10秒
$last_response=time();//开始时间
ob_隐式_刷新(真);
ob_end_flush();
$descriptorspec=数组(
0=>array(“pipe”,“r”),//stdin是子级将从中读取的管道
1=>array(“pipe”,“w”),//stdout是子级将写入的管道
2=>array(“pipe”,“w”)//stderr是子级将写入的管道
);
冲洗();
$process=proc_open($cmd、$descriptorspec、$pipes、realpath('./')、array());
回声“;
如果(是_资源($process)){
而($s=fgets($pipes[1])){
打印$s;
if((time()-$last\u response)>$timeout\u容差){
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
过程结束($过程);
}
$last_response=time();
冲洗();
}
}
回声“;
将此脚本作为单独的脚本运行,可以调用您发布的脚本,查找回音,如果没有收到回音,请尝试以下操作:

$cmd = "php AnalyzeFriends.php";
$timeout_tolerance = 10; // 10 seconds
$last_response = time(); // start time

ob_implicit_flush(true);
ob_end_flush();

$descriptorspec = array(
   0 => array("pipe", "r"),   // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),   // stdout is a pipe that the child will write to
   2 => array("pipe", "w")    // stderr is a pipe that the child will write to
);
flush();
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo "<pre>";
if (is_resource($process)) {
    while ($s = fgets($pipes[1])) {
        print $s;
        if((time() - $last_response) > $timeout_tolerance){
          fclose($pipes[0]);
          fclose($pipes[1]);
          fclose($pipes[2]);
          proc_close($process);
        }
        $last_response = time();
        flush();
    }
}
echo "</pre>";
$cmd=“php AnalyzeFriends.php”;
$timeout\u公差=10;//10秒
$last_response=time();//开始时间
ob_隐式_刷新(真);
ob_end_flush();
$descriptorspec=数组(
0=>array(“pipe”,“r”),//stdin是子级将从中读取的管道
1=>array(“pipe”,“w”),//stdout是子级将写入的管道
2=>array(“pipe”,“w”)//stderr是子级将写入的管道
);
冲洗();
$process=proc_open($cmd、$descriptorspec、$pipes、realpath('./')、array());
回声“;
如果(是_资源($process)){
而($s=fgets($pipes[1])){
打印$s;
if((time()-$last\u response)>$timeout\u容差){
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
过程结束($过程);
}
$last_response=time();
冲洗();
}
}
回声“;

将此脚本作为单独的脚本运行,可以调用您发布的脚本,查找回音,如果没有收到回音,请添加代码。阅读此处了解如何形成@amflare。这里是一个示例。请添加您的代码。阅读此处了解如何形成@amflare这里有一个示例感谢您的回答,
$pipe
变量代表什么?感谢您的回答,
$pipe
变量代表什么?