xref: /PHP-7.4/ext/curl/tests/curl_basic_006.phpt (revision d6c05c6c)
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--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
16  include 'server.inc';
17  $host = curl_cli_server_start();
18
19  // start testing
20  echo '*** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***' . "\n";
21
22  $url = "{$host}/get.inc?test=get";
23  $ch = curl_init();
24  $alldata = '';
25  ob_start(); // start output buffering
26  curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
27  curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
28    $GLOBALS['alldata'] .= $data;
29    return strlen ($data);
30  });
31
32  curl_exec($ch);
33  curl_close($ch);
34  ob_end_flush();
35  echo "Data: $alldata";
36?>
37===DONE===
38--EXPECT--
39*** Testing curl_setopt($ch, CURLOPT_WRITEFUNCTION, <closure>); ***
40Data: Hello World!
41Hello World!===DONE===
42