async-http-php是个异步HTTP客户端,机遇crul_mulit*,系统很简单,速度非常快。
如果你想使用ssl或者其他来请求一个网站,你可以实现一个task类和TaskInterface接口:
date_default_timezone_set("PRC");require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';$async = new \Jenner\Http\Async();$task = \Jenner\Http\Task::createGet("https://www.baidu.com");$async->attach($task, "baidu");$task2 = \Jenner\Http\Task::createGet("https://www.sina.com");$async->attach($task2, "sina");$task3 = \Jenner\Http\Task::createGet("https://www.qq.com");$async->attach($task3, "qq");/** * you can do something here before receive the http responses * eg. query data from mysql or redis. */while(true){ // nonblock if(!$async->isDone()){ echo "I am running" . PHP_EOL; sleep(1); continue; } $result = $async->execute(); print_r($result); break;}/** * or you just call execute. it will block the process until all tasks are done. * $result = $async->execute(); * print_r($result); */
评论