PHP脚本可以启动另一个PHP脚本和退出? [英] Can a PHP script start another PHP script and exit?

查看:553
本文介绍了PHP脚本可以启动另一个PHP脚本和退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP脚本启动另一个PHP脚本,然后退出,让其它的脚本来运行?

How can a PHP script start another PHP script, and then exit, leaving the other script running?

此外,有没有什么办法的第二个脚本,当它达到一个特定的行通知PHP脚本?

Also, is there any way for the 2nd script to inform the PHP script when it reaches a particular line?

推荐答案

下面是如何做到这一点。你告诉浏览器输出的前N个字符阅读,然后关闭连接,而你的脚本继续工作,直到它完成。

Here's how to do it. You tell the browser to read in the first N characters of output and then close the connection, while your script keeps running until it's done.

<?php
ob_end_clean();
header("Connection: close");
ignore_user_abort(); // optional
ob_start();
echo ('Text the user will see');
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();     // Will not work
flush();            // Unless both are called !

// At this point, the browser has closed connection to the web server

// Do processing here
include('other_script.php');

echo('Text user will never see');
?>

这篇关于PHP脚本可以启动另一个PHP脚本和退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆