curl.php 442 B

12345678910111213141516171819
  1. <?php
  2. Swoole\Runtime::enableCoroutine();
  3. go(function () {
  4. $ch = curl_init();
  5. curl_setopt($ch, CURLOPT_URL, "http://www.gov.cn/xinwen/index.htm");
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_HEADER, 0);
  8. $output = curl_exec($ch);
  9. if ($output === FALSE) {
  10. echo "CURL Error:" . curl_error($ch);
  11. }
  12. curl_close($ch);
  13. echo strlen($output) . "bytes\n";
  14. });
  15. swoole_event_wait();