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