Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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_Ajax_Shell_Concurrency_Exec - Fatal编程技术网

在后台运行PHP脚本

在后台运行PHP脚本,php,ajax,shell,concurrency,exec,Php,Ajax,Shell,Concurrency,Exec,我有两个PHP脚本,我们将它们称为脚本A和脚本B。当用户进行某种交互时,脚本A开始运行。脚本A需要在后台运行脚本B,从而在脚本B仍在运行时返回脚本A的结果。我可以在脚本A中执行此操作: 执行'scriptB.php&',但由于我在共享主机上,因此不允许执行。另外,Ajax解决方案在客户端启动这两个脚本将无法工作,因为脚本B必须运行——我不能让用户恶意阻止脚本运行 有没有不使用shell命令或Ajax的解决方案 提前谢谢 我最终使用了这种方法: 瑞秋,谢谢你的帮助 function backgr

我有两个PHP脚本,我们将它们称为脚本A和脚本B。当用户进行某种交互时,脚本A开始运行。脚本A需要在后台运行脚本B,从而在脚本B仍在运行时返回脚本A的结果。我可以在脚本A中执行此操作: 执行'scriptB.php&',但由于我在共享主机上,因此不允许执行。另外,Ajax解决方案在客户端启动这两个脚本将无法工作,因为脚本B必须运行——我不能让用户恶意阻止脚本运行

有没有不使用shell命令或Ajax的解决方案


提前谢谢

我最终使用了这种方法:

瑞秋,谢谢你的帮助

function backgroundPost($url){
    $parts=parse_url($url);
    $fp = fsockopen($parts['host'], 
        isset($parts['port'])?$parts['port']:80, 
        $errno, $errstr, 30);
    if (!$fp) {
        return false;
    } else {
        $out = "POST ".$parts['path']." HTTP/1.1\r\n";
        $out.= "Host: ".$parts['host']."\r\n";
        $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
        $out.= "Content-Length: ".strlen($parts['query'])."\r\n";
        $out.= "Connection: Close\r\n\r\n";
        if (isset($parts['query'])) $out.= $parts['query'];
        fwrite($fp, $out);
        fclose($fp);
        return true;
    }
}

//Example of use
backgroundPost('http://example.com/slow.php?file='.urlencode('some file.dat'));