xref: /PHP-7.3/ext/curl/tests/curl_basic_017.phpt (revision 782352c5)
1--TEST--
2Test curl_multi_exec() 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_multi_exec(resource ch)
10 * Description: Perform a cURL session
11 * Source code: ext/curl/multi.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  curl_setopt($chs[0], CURLOPT_URL, $url); //set the url we want to use
31  curl_setopt($chs[1], CURLOPT_URL, $url); //set the url we want to use
32  curl_setopt($chs[2], CURLOPT_URL, $url); //set the url we want to use
33
34  $mh = curl_multi_init();
35
36  // add handlers
37  curl_multi_add_handle($mh, $chs[0]);
38  curl_multi_add_handle($mh, $chs[1]);
39  curl_multi_add_handle($mh, $chs[2]);
40
41  $running=null;
42  //execute the handles
43  $state = null;
44  do {
45    $state = curl_multi_exec($mh, $running);
46  } while ($running > 0);
47
48  //close the handles
49  curl_multi_remove_handle($mh, $chs[0]);
50  curl_multi_remove_handle($mh, $chs[1]);
51  curl_multi_remove_handle($mh, $chs[2]);
52  curl_multi_close($mh);
53
54  $curl_content = ob_get_contents();
55  ob_end_clean();
56
57  if($state === CURLM_OK) {
58    var_dump( $curl_content );
59  } else {
60    echo "curl_exec returned false";
61  }
62?>
63===DONE===
64--EXPECT--
65*** Testing curl_exec() : basic functionality ***
66string(75) "Hello World!
67Hello World!Hello World!
68Hello World!Hello World!
69Hello World!"
70===DONE===
71