php有调用脚本后立即返回的函数吗?该怎么处理

WBOY
Release: 2016-06-13 13:33:53
Original
679 people have browsed it

php有调用脚本后立即返回的函数吗?
比如有一个php文件a.php,它大概要2分钟才能执行完,有没有一个函数,可以让这个文件执行,不等它执行完呢?

就是只要唤醒a.php让它执行就行,主程序立即返回处理别的事情。

------解决方案--------------------
fsockopen() 函数兴许能解决你的问题
http://qianxunniao.iteye.com/blog/1243602
------解决方案--------------------
test 怎么老吃我的回复?
你也可以用php调用外部命令执行b.php
------解决方案--------------------
给你个函数,在我多个环境中可用。
但不保证在你呢环境中有用

PHP code
/**
 * 函数 tenor
 * 功能 启动一个url,但不等待返回
 * 参数 $page,待执行的页面程序
 * 返回 无
 **/
if(! function_exists('tenor')):
function tenor($page) {
        $host = $_SERVER["HTTP_HOST"];
        $fp = fsockopen($host, 80, $errno, $errmsg);
        if(!$fp) {
                echo "$errstr ($errno)<br>\n";
        } else {
                fputs($fp,"GET /$page HTTP/1.0\nHost: $host\n\n");
                fclose($fp);//可能需要注释掉该行
        }
}
endif;
<br><font color="#e78608">------解决方案--------------------</font><br>php 是不支持多线程的,更谈不上主线程和子线程了。  不过倒是有办法模拟这个环境,代码如下:<br>do {<br> ?                        $mrc = curl_multi_exec($mh,$active);<br> ?                } while ($mrc == CURLM_CALL_MULTI_PERFORM);<br> ?                while ($active and $mrc == CURLM_OK) {<br> ?                        if (curl_multi_select($mh) != -1) {<br> ?                                do {<br> ?                                        $mrc = curl_multi_exec($mh, $active);<br> ?                                } while ($mrc == CURLM_CALL_MULTI_PERFORM);<br> ?                        }<br> ?                }<br> ?是通过一个不停执行的循环 模拟的,<br><br>这个办法要是不行的话  就用系统的计划任务  定时去执行程序吧~
<br><font color="#e78608">------解决方案--------------------</font><br>这种事还是用C吧, php只是为了Web而活的。。<br><br>具体程序架构怎么设计还得明确一下功能描述。 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!