Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.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脚本-windows_Php_Windows_Background - Fatal编程技术网

在后台运行php脚本-windows

在后台运行php脚本-windows,php,windows,background,Php,Windows,Background,我想在另一个php页面的后台运行一个无限循环的php脚本,而不会停止或影响调用者页面, 到目前为止,我尝试的是: 在调用方页面中: set_time_limit(0); ignore_user_abort(true); $path=realpath('./infinity.php'); $cmd='c:/xampp/php/php'.$path; if (substr(php_uname(), 0, 7) == "Windows"){ exec("start/b C:\\xampp\\

我想在另一个php页面的后台运行一个无限循环的php脚本,而不会停止或影响调用者页面, 到目前为止,我尝试的是: 在调用方页面中:

set_time_limit(0);
ignore_user_abort(true); 
$path=realpath('./infinity.php');
$cmd='c:/xampp/php/php'.$path;
if (substr(php_uname(), 0, 7) == "Windows"){ 
   exec("start/b C:\\xampp\\php\\php $path > NUL");
} 
else { 
    exec($cmd . " > /dev/null &");   
} 
在infinity.php中

set_time_limit(0);
ignore_user_abort(true); 
我的问题是,当我试图在浏览器中打开调用者页面时,我会永远看到加载标记,而页面永远不会打开

你能告诉我我错过了什么吗? 注意: -我在用Windows8 -我在这两个页面中都使用了set_time_limit(0)和ignore_user_abort(true),因为我不知道应该如何准确地使用它们

我知道我的问题可能会重复,但我已经尝试了所有建议的解决方案,仍然无法打开调用方页面


非常感谢您提供的任何帮助

这对我很有用,但请注意,这是在Linux设备上

$cmd = "/path/to/script/to/run/in/background.php $var1 $var2";
$outputfile = '/path/to/script/output.txt';
$pidfile = '/path/to/process/id/file.txt';
$exe = exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
这将在第一个脚本之外的shell中运行background.php。第一个脚本将继续正常运行,而不是等待background.php完成。由于脚本将在后台运行,因此获取PID并将其存储在某个位置非常重要,这样您就可以随时检查脚本。i、 它还在运行吗。outputfile和pidfile需要可由脚本写入


很抱歉,在我意识到您在windows环境中工作之前,我就开始撰写此回复!也许还是有用的。(可能不是…)

PHP不是异步或多线程的。无限循环将阻止任何其他进程,直到它退出。你可以看看其他更适合这个问题的技术,或者澄清你为什么需要这样做(我们可能会建议一个更好的PHP选项)。知道这在linux而不是windows中是可能的人只会找到你的答案。