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

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

Jun 13, 2016 pm 01:33 PM
host multi php quot

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
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles