curl_write_callback.phpt 794 B

123456789101112131415161718192021222324252627282930313233343536
  1. --TEST--
  2. Test curl option CURLOPT_WRITEFUNCTION
  3. --CREDITS--
  4. Mathieu Kooiman <mathieuk@gmail.com>
  5. Dutch UG, TestFest 2009, Utrecht
  6. --DESCRIPTION--
  7. Writes the value 'test' to a temporary file. Use curl to access this file, passing the output into a callback. Tests the PHP_CURL_USER case in curl_write.
  8. --EXTENSIONS--
  9. curl
  10. --FILE--
  11. <?php
  12. function curl_callback($curl_handle, $received_data)
  13. {
  14. echo $received_data;
  15. return strlen($received_data);
  16. }
  17. $log_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
  18. $fp = fopen($log_file, 'w+');
  19. fwrite($fp, "test");
  20. fclose($fp);
  21. $ch = curl_init();
  22. curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'curl_callback');
  23. curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
  24. curl_exec($ch);
  25. curl_close($ch);
  26. // cleanup
  27. unlink($log_file);
  28. ?>
  29. --EXPECT--
  30. test