xref: /PHP-7.3/ext/curl/tests/curl_basic_018.phpt (revision 782352c5)
1--TEST--
2Test curl_setopt() with curl_multi function with basic functionality
3--CREDITS--
4TestFest 2009 - AFUP - Thomas Rabaix <thomas.rabaix@gmail.com>
5--SKIPIF--
6<?php include 'skipif.inc'; ?>
7--FILE--
8<?php
9/* Prototype  : bool curl_setopt(resource ch, int option, mixed value)
10 * Description: Set an option for a cURL transfer
11 * Source code: ext/curl/interface.c
12 * Alias to functions:
13 */
14
15  include 'server.inc';
16  $host = curl_cli_server_start();
17
18  // start testing
19  echo "*** Testing curl_exec() : basic functionality ***\n";
20
21  $url = "{$host}/get.php?test=get";
22  $chs = array(
23    0 => curl_init(),
24    1 => curl_init(),
25    2 => curl_init(),
26  );
27
28  ob_start(); // start output buffering
29
30  $options = array(
31    CURLOPT_RETURNTRANSFER => 1,
32    CURLOPT_URL => $url,
33  );
34
35  curl_setopt_array($chs[0], $options); //set the options
36  curl_setopt_array($chs[1], $options); //set the options
37  curl_setopt_array($chs[2], $options); //set the options
38
39  $mh = curl_multi_init();
40
41  // add handlers
42  curl_multi_add_handle($mh, $chs[0]);
43  curl_multi_add_handle($mh, $chs[1]);
44  curl_multi_add_handle($mh, $chs[2]);
45
46  $running=null;
47  //execute the handles
48  do {
49    curl_multi_exec($mh, $running);
50  } while ($running > 0);
51
52  $curl_content = '';
53  $curl_content .= curl_multi_getcontent($chs[0]);
54  $curl_content .= curl_multi_getcontent($chs[1]);
55  $curl_content .= curl_multi_getcontent($chs[2]);
56
57  //close the handles
58  curl_multi_remove_handle($mh, $chs[0]);
59  curl_multi_remove_handle($mh, $chs[1]);
60  curl_multi_remove_handle($mh, $chs[2]);
61  curl_multi_close($mh);
62
63  var_dump( $curl_content );
64
65?>
66===DONE===
67--EXPECT--
68*** Testing curl_exec() : basic functionality ***
69string(75) "Hello World!
70Hello World!Hello World!
71Hello World!Hello World!
72Hello World!"
73===DONE===
74