basic.php 882 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once '_inc.php';
  3. use Ares333\Curl\Toolkit;
  4. $toolkit = new Toolkit();
  5. $toolkit->setCurl();
  6. $curl = $toolkit->getCurl();
  7. $curl->onInfo = null;
  8. $responseCode = null;
  9. $curl->add(
  10. array(
  11. 'opt' => array(
  12. CURLOPT_URL => 'http://baidu.com'
  13. ),
  14. 'args' => [
  15. 'This is user arg',
  16. &$responseCode
  17. ]
  18. ),
  19. function ($r, $args) {
  20. $args[1] = $r['info']['http_code'];
  21. echo "Request success for " . $r['info']['url'] . "\n";
  22. echo "\nHeader info:\n";
  23. print_r($r['info']);
  24. echo "\nRaw header:\n";
  25. print_r($r['header']);
  26. echo "\nArgs:\n";
  27. print_r($args);
  28. echo "\n\nBody size:\n";
  29. echo strlen($r['body']) . ' bytes';
  30. echo "\n";
  31. });
  32. $curl->start();
  33. echo "\nresponse code returned by reference:\n";
  34. echo $responseCode . "\n";