curl_basic_006.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. --SKIPIF--
  7. <?php include 'skipif.inc'; ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : bool curl_setopt(resource ch, int option, mixed value)
  11. * Description: Set an option for a cURL transfer
  12. * Source code: ext/curl/interface.c
  13. * Alias to functions:
  14. */
  15. include 'server.inc';
  16. $host = curl_cli_server_start();
  17. // start testing
  18. echo '*** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***' . "\n";
  19. $url = "{$host}/get.php?test=get";
  20. $ch = curl_init();
  21. $alldata = '';
  22. ob_start(); // start output buffering
  23. curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
  24. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
  25. $GLOBALS['alldata'] .= $data;
  26. return strlen ($data);
  27. });
  28. curl_exec($ch);
  29. curl_close($ch);
  30. ob_end_flush();
  31. echo "Data: $alldata";
  32. ?>
  33. ===DONE===
  34. --EXPECTF--
  35. *** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***
  36. Data: Hello World!
  37. Hello World!===DONE===