php httpresponse,发送HTTP响应后继续执行PHP

一个人可以对自己或任何其他脚本使用“ http fork”。我的意思是这样的:

// parent sript, called by user request from browser

// create socket for calling child script

$socketToChild = fsockopen("localhost", 80);

// HTTP-packet building; header first

$msgToChild = "POST /sript.php?&param=value& HTTP/1.0\n";

$msgToChild .= "Host: localhost\n";

$postData = "Any data for child as POST-query";

$msgToChild .= "Content-Length: ".strlen($postData)."\n\n";

// header done, glue with data

$msgToChild .= $postData;

// send packet no oneself www-server - new process will be created to handle our query

fwrite($socketToChild, $msgToChild);

// wait and read answer from child

$data = fread($socketToChild, $dataSize);

// close connection to child

fclose($socketToChild);

...

现在,子脚本:

// parse HTTP-query somewhere and somehow before this point

// "disable partial output" or

// "enable buffering" to give out all at once later

ob_start();

// "say hello" to client (parent script in this case) disconnection

// before child ends - we need not care about it

ignore_user_abort(1);

// we will work forever

set_time_limit(0);

// we need to say something to parent to stop its waiting

// it could be something useful like client ID or just "OK"

...

echo $reply;

// push buffer to parent

ob_flush();

// parent gets our answer and disconnects

// but we can work "in background" :)

...

主要思想是:

用户请求调用的父脚本;

父级在同一台服务器(或任何其他服务器)上调用子级脚本(与父级或另一个)相同,并向它们提供请求数据;

父母对用户说可以并结束;

儿童作品。

如果您需要与孩子互动-可以将DB用作“通信介质”:父母可以读取孩子的状态并写入命令,孩子可以读取命令并写入状态。如果您需要几个子脚本,则应在用户侧保留子ID以区别它们,并在每次要检查各自子状态时将其ID发送给父。

我在这里找到了-http: //linuxportal.ru/forums/index.php/t/22951/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值