xref: /PHP-5.3/ext/curl/tests/curl_basic_018.phpt (revision 84b17658)
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 if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
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  $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  $options = array(
30    CURLOPT_RETURNTRANSFER => 1,
31    CURLOPT_URL => $url,
32  );
33
34  curl_setopt_array($chs[0], $options); //set the options
35  curl_setopt_array($chs[1], $options); //set the options
36  curl_setopt_array($chs[2], $options); //set the options
37
38  $mh = curl_multi_init();
39
40  // add handlers
41  curl_multi_add_handle($mh, $chs[0]);
42  curl_multi_add_handle($mh, $chs[1]);
43  curl_multi_add_handle($mh, $chs[2]);
44
45  $running=null;
46  //execute the handles
47  do {
48    curl_multi_exec($mh, $running);
49  } while ($running > 0);
50
51  $curl_content = '';
52  $curl_content .= curl_multi_getcontent($chs[0]);
53  $curl_content .= curl_multi_getcontent($chs[1]);
54  $curl_content .= curl_multi_getcontent($chs[2]);
55
56  //close the handles
57  curl_multi_remove_handle($mh, $chs[0]);
58  curl_multi_remove_handle($mh, $chs[1]);
59  curl_multi_remove_handle($mh, $chs[2]);
60  curl_multi_close($mh);
61
62  var_dump( $curl_content );
63
64?>
65===DONE===
66--EXPECTF--
67*** Testing curl_exec() : basic functionality ***
68%unicode|string%(75) "Hello World!
69Hello World!Hello World!
70Hello World!Hello World!
71Hello World!"
72===DONE===
73