有一个异步方法如下:
function hello($message,$test,$txt){
for($k=0;$k<$con;$k++)
{
$fp=fsockopen('localhost',8080,&$errno,&$errstr,5);
fwrite($fp,"GET /Hello/js_push?message=".$message."&test=".$test."&txt=".$txt." \r\n");
}
}
js_push函数如下:
function js_push(){
ignore_user_abort();
set_time_limit(0);
...
fwrite($fps, date('Y-m-d H:i:s').$value." \r\n");
...
}
问题:我想要在js_push里加一个回调函数,使每次的fwrite($fps, date('Y-m-d H:i:s').$value." \r\n");执行完之后,再去执行上面for循环里的第二,第三,,,
要如何实现呢?php异步for
function hello($message,$test,$txt){
for($k=0;$k<$con;$k++)
{
$fp=fsockopen('localhost',8080,&$errno,&$errstr,5);
fwrite($fp,"GET /Hello/js_push?message=".$message."&test=".$test."&txt=".$txt." \r\n");
}
}
js_push函数如下:
function js_push(){
ignore_user_abort();
set_time_limit(0);
...
fwrite($fps, date('Y-m-d H:i:s').$value." \r\n");
...
}
问题:我想要在js_push里加一个回调函数,使每次的fwrite($fps, date('Y-m-d H:i:s').$value." \r\n");执行完之后,再去执行上面for循环里的第二,第三,,,
要如何实现呢?php异步for
while(fgets($fp));
就可以了
function hello($message,$test,$txt){
for($k=0;$k<$con;$k++)
{
$fp=fsockopen('localhost',8080,&$errno,&$errstr,5);
js_push();
fwrite($fp,"GET /Hello/js_push?message=".$message."&test=".$test."&txt=".$txt." \r\n");
}
}这样不行么?
执行完之后,再去执行上面for循环里的第二,第三,,,不就是等待的意思吗?
所以才说
就算想模拟实现多线程、进程,也只能依靠系统和外部模块
还有,如果我想让for循环10次,再执行一次while(fgets($fp));要怎么实现呢?