xref: /PHP-5.3/ext/curl/tests/curl_basic_017.phpt (revision 84b17658)
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 if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
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  $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
16
17  // start testing
18  echo "*** Testing curl_exec() : basic functionality ***\n";
19
20  $url = "{$host}/get.php?test=get";
21  $chs = array(
22    0 => curl_init(),
23    1 => curl_init(),
24    2 => curl_init(),
25  );
26
27  ob_start(); // start output buffering
28
29  curl_setopt($chs[0], CURLOPT_URL, $url); //set the url we want to use
30  curl_setopt($chs[1], CURLOPT_URL, $url); //set the url we want to use
31  curl_setopt($chs[2], CURLOPT_URL, $url); //set the url we want to use
32
33  $mh = curl_multi_init();
34
35  // add handlers
36  curl_multi_add_handle($mh, $chs[0]);
37  curl_multi_add_handle($mh, $chs[1]);
38  curl_multi_add_handle($mh, $chs[2]);
39
40  $running=null;
41  //execute the handles
42  $state = null;
43  do {
44    $state = curl_multi_exec($mh, $running);
45  } while ($running > 0);
46
47  //close the handles
48  curl_multi_remove_handle($mh, $chs[0]);
49  curl_multi_remove_handle($mh, $chs[1]);
50  curl_multi_remove_handle($mh, $chs[2]);
51  curl_multi_close($mh);
52
53  $curl_content = ob_get_contents();
54  ob_end_clean();
55
56  if($state === CURLM_OK) {
57    var_dump( $curl_content );
58  } else {
59    echo "curl_exec returned false";
60  }
61?>
62===DONE===
63--EXPECTF--
64*** Testing curl_exec() : basic functionality ***
65string(75) "Hello World!
66Hello World!Hello World!
67Hello World!Hello World!
68Hello World!"
69===DONE===
70