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