curl_basic_006.phpt 900 B

1234567891011121314151617181920212223242526272829303132333435
  1. --TEST--
  2. Test curl_opt() function with CURLOPT_WRITEFUNCTION parameter set to a closure
  3. --CREDITS--
  4. ?
  5. TestFest 2009 - AFUP - Jean-Marc Fontaine <jmf@durcommefaire.net>
  6. --EXTENSIONS--
  7. curl
  8. --FILE--
  9. <?php
  10. include 'server.inc';
  11. $host = curl_cli_server_start();
  12. // start testing
  13. echo '*** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***' . "\n";
  14. $url = "{$host}/get.inc?test=get";
  15. $ch = curl_init();
  16. $alldata = '';
  17. ob_start(); // start output buffering
  18. curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
  19. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
  20. $GLOBALS['alldata'] .= $data;
  21. return strlen ($data);
  22. });
  23. curl_exec($ch);
  24. curl_close($ch);
  25. ob_end_flush();
  26. echo "Data: $alldata";
  27. ?>
  28. ===DONE===
  29. --EXPECT--
  30. *** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***
  31. Data: Hello World!
  32. Hello World!===DONE===