hook.php 853 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. Co::set(['hook_flags' => SWOOLE_HOOK_ALL | SWOOLE_HOOK_NATIVE_CURL, ]);
  3. //Co::set(['hook_flags' => SWOOLE_HOOK_ALL, ]);
  4. Co\run(function () {
  5. $n = 3000;
  6. while($n--) {
  7. go('test');
  8. }
  9. });
  10. function test() {
  11. echo "curl init\n";
  12. $ch = curl_init();
  13. $url = 'https://www.baidu.com/';
  14. // $url = "http://127.0.0.1:9801/";
  15. curl_setopt($ch, CURLOPT_URL, $url);
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  17. curl_setopt($ch, CURLOPT_HEADER, 0);
  18. curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $strHeader) {
  19. //var_dump($ch, $strHeader);
  20. return strlen($strHeader);
  21. });
  22. $output = curl_exec($ch);
  23. var_dump($output);
  24. var_dump(strlen($output));
  25. if ($output === false) {
  26. echo "CURL Error:" . curl_error($ch);
  27. }
  28. // var_dump($output);
  29. curl_close($ch);
  30. }