我有一个php文件来创建一个目录。我希望php文件在后台执行。我写了2个文件如下。
file1.php
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
echo 'calling file1';
if(!is_dir('testdir')){
mkdir('testdir');
}
?>
的index.php
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$i = '';
exec("php file1.php $i > test.txt &");
?>
我希望通过浏览器执行index.php时创建一个目录。我想我写错了写exec()函数。谁能告诉我它会是怎样的?
答案 0 :(得分:0)
所以,答案是使用CURL,因为你不需要使用任何PHP二进制文件。
如果你不希望file1.php等到file2.php完成对file1上的cUrl请求添加超时:
$curlcontext,CURLOPT_CONNECTTIMEOUT_MS,100;
现在,将它添加到file2.php是很重要的:
ignore_user_abort (true);
这意味着file2.php在超时或file1.php
之后不会终止http://php.net/manual/en/function.ignore-user-abort.php http://php.net/manual/en/function.curl-setopt.php