使用http在后台运行php

编程入门 行业动态 更新时间:2024-10-19 22:38:18
本文介绍了使用http在后台运行php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

i有一个脚本(script1)需要调用另一个脚本(script2)。 它不应该等待答案,所以script2应该在后台运行。 我真的需要使用以下方法调用php脚本: http:// urlof myscript / script2.php 我不想将它用作cgi并使用CLI。 我用fsockopen和curl进行测试,超时10秒并调用 http:// urlof 来自浏览器的myscript / script1.php: Script1在10秒后停止=> OK Script2已被script1调用并继续在后台运行 => OK 60秒后Script2被php杀死! => KO :( 如果我打电话给 http:// urlof,脚本工作正常 myscript / script2.php来自 我的浏览器。它需要大约120秒才能完成。 为什么它会在60秒后停止使用fsockopen并从 script1调用它? 以下是SCRIPT1中的脚本: $ fp = fsockopen(" $ host",80,$ errno,$ errstr,30); stream_set_timeout($ fp,10); if(!$ fp){ echo" $ errstr($ errno)< br /> \ n" ;; } else { $ out =" GET $ path HTTP / 1.1\r\\\" ;; $ out。=" Host:$ host\r\\\" ;; $ out。= 连接:关闭\\\\\ nn ;; fwrite($ fp,$ out); $ status = socket_get_status($ fp); while(!feof($ fp)&&!$ status [''timed_out'']){ echo fgets($ fp,128); $ status = socket_get_status($ fp); } fclose($ fp); } 我在SCRIPT2中添加了这个: ignore_user_abort(FALSE); // becareful,FALSE真的意味着它应该忽略 用户中止!!! set_time_limit(120); ini_set(" max_input_time" ,120); ini_set(" max_execution_time",120); 你有什么想法吗? 谢谢你的帮助 Rod

Hi, i have a script (script1) which needs to call another script (script2). It should not wait for the answer, so script2 should run in the background. I really need to call the php script using: urlof myscript/script2.php I don''t want to use it as a cgi and use CLI. I did a test with fsockopen and curl and a timeout of 10 seconds and call urlof myscript/script1.php from my browser: Script1 stops after 10 seconds => OK Script2 has been called by script1 and continue to run in the background =>OK After 60 seconds Script2 is killed by php!! => KO :( The script is working fine if i call urlof myscript/script2.php from my browser. It needs around 120 seconds to finish. Why is it stopping after 60 seconds when I use fsockopen and call it from script1? Here is the script in SCRIPT1: $fp = fsockopen("$host", 80, $errno, $errstr, 30); stream_set_timeout($fp,10); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET $path HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); $status = socket_get_status($fp); while (!feof($fp) && !$status[''timed_out'']) { echo fgets($fp, 128); $status = socket_get_status($fp); } fclose($fp); } I have added this in SCRIPT2: ignore_user_abort(FALSE); // becareful, FALSE really means it should ignore user abort !!! set_time_limit (120); ini_set("max_input_time",120); ini_set("max_execution_time",120); Do you have any idea?? Thanks you for your help Rod

推荐答案

fp = fsockopen(" fp = fsockopen("

host",80, host", 80,

errno,

更多推荐

使用http在后台运行php

本文发布于:2023-11-25 23:55:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631843.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   http   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!