求教 :协成包装后无法执行问题

无法执行代码



$server = new Swoole\Http\Server("127.0.0.1", 9502, SWOOLE_BASE);
$server->set([
    'worker_num' => 1,
]);
$server->on('Request', function ($request, \Swoole\Http\Response $response) {

//    $httpclient = new Swoole\Coroutine\Http\Client('127.0.0.1', 80);
//    $httpclient->setHeaders(['Host' => 'localhost']);
//    $httpclient->set([ 'timeout' => 5]);
//    $httpclient->get('/c.php');
//    $http_res = $httpclient->body;


    $http_res = http_get('127.0.0.1','localhost','/c.php');
    //没有执行到这里
    echo 'aaaa';
    $response->end($http_res);
});
$server->start();


function http_get($ip,$host,$path){
    $httpclient = new Swoole\Coroutine\Http\Client($ip, 80);
    $httpclient->setHeaders(['Host' => $host]);
    $httpclient->set([ 'timeout' => 5]);
    $httpclient->get($path);
    $res = $httpclient->body;
    //这里有执行
    echo 'eeeeww';
    return $res;
}

同样的代码 为什么通过 函数包装后就无法执行了呢?有没有任何错误。感觉像是阻塞在 http_get 这个函数了。

2018-04-23 20:38
0
0

探索者 - one框架 -- 极简的基于swoole常驻内存框架

赞同来自:

配置信息:

swoole swoole support => enabled Version => 2.1.1 Author => tianfeng.han[email: mikan.tenny@gmail.com] coroutine => enabled kqueue => enabled rwlock => enabled async http/websocket client => enabled pcre => enabled zlib => enabled Directive => Local Value => Master Value swoole.aio_thread_num => 2 => 2 swoole.display_errors => On => On swoole.fast_serialize => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608 swoole.use_namespace => On => On swoole.use_shortname => On => On

系统环境: macos high sierra 10.13.3

2018-04-23 20:49
0

探索者 - one框架 -- 极简的基于swoole常驻内存框架

赞同来自:

升级到2.1.3还是不行。 但是在centos下可以。 可能是和系统有关吧

2018-04-23 21:37
0

mc - swoole已被地外生命关注

赞同来自:

Mac下swoole 4.0 试试,应该是正常的

2018-06-14 15:04

要回复问题请先登录注册