rend 未定义,是什么原因?

来源:6-3 Swoole进程案例解刨

小白学编程666

2019-01-19

echo "process-start-time:".date('Y-m-d H:i:s').PHP_EOL;
$workers = [];
$curls = [
    'http://baidu.com',
    'http://sina.com.cn',
    'http://qq.com',
    'https://www.baidu.com/s?wd=imooc',
    'https://www.baidu.com/s?wd=wnaglei',
    'https://www.baidu.com/s?wd=wangmin',
];

for ($i=0; $i<6; $i++) {
    $process = new swoole_process(function (swoole_process $worder) use($i, $curls) {
        $content = curlData($curls[$i]);
//        echo $content.PHP_EOL;
        $worder->write($content.PHP_EOL);
    }, true);
    $pid = $process->start();
    $workers[$pid] = $process;
}

foreach ($workers as $process) {
    echo $process->rend();
}

function curlData($curl) {
    sleep(1);
    return $curl.'success'.PHP_EOL;
}

echo "process-end-time:".date('Y-m-d H:i:s').PHP_EOL;

报错:

process-start-time:2019-01-19 04:37:38
PHP Fatal error:  Uncaught Error: Call to undefined method Swoole\Process::rend() in /Users/alanwang/wwwroot/demo/process/curl.php:31
Stack trace:

写回答

4回答

慕粉慕粉1888

2020-01-28

应该是read吧,你写成了rend

0
0

小白学编程666

提问者

2019-01-21

//img.mukewang.com/szimg/5c45262b00019c5515741714.jpg打印$process返回的

0
0

singwa

2019-01-19

同学您好。您打印$process 试试 看看返回什么内容呢?

print_r($process);

0
1
小白学编程666
一个对象: Swoole\Process Object { [pipe] => 4,[callback] =>Closure Object,[msgQueueId] => [msgQueueKey] => [pid] => 71317 [id] =>
2019-01-21
共1条回复

singwa

2019-01-19

同学你好请问你的swoole是哪个版本?

0
1
小白学编程666
4.2
2019-01-19
共1条回复

Swoole入门到实战打造高性能赛事直播平台

swoole创始人推荐,借助Swoole打造高性能直播平台

2228 学习 · 1062 问题

查看课程