2009-07-03 00:09:08 +00:00
|
|
|
--TEST--
|
|
|
|
curl_setopt_array() function - tests setting multiple cURL options with curl_setopt_array()
|
|
|
|
--CREDITS--
|
|
|
|
Mattijs Hoitink mattijshoitink@gmail.com
|
|
|
|
#Testfest Utrecht 2009
|
|
|
|
--SKIPIF--
|
|
|
|
<?php if (!extension_loaded("curl")) print "skip"; ?>
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Prototype: bool curl_setopt_array(resource $ch, array $options)
|
|
|
|
* Description: Sets multiple options for a cURL session.
|
|
|
|
* Source: ext/curl/interface.c
|
|
|
|
* Documentation: http://wiki.php.net/qa/temp/ext/curl
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Figure out what handler to use
|
2009-07-25 14:52:52 +00:00
|
|
|
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
|
|
|
|
if (!empty($host)) {
|
2009-07-03 00:09:08 +00:00
|
|
|
// Use the set Environment variable
|
|
|
|
$url = "{$host}/get.php?test=get";
|
|
|
|
} else {
|
|
|
|
// Create a temporary file for the test
|
|
|
|
$tempname = tempnam(sys_get_temp_dir(), 'CURL_HANDLE');
|
|
|
|
$url = 'file://'. $tempname;
|
|
|
|
// add the test data to the file
|
|
|
|
file_put_contents($tempname, "Hello World!\nHello World!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the test
|
|
|
|
echo '== Starting test curl_setopt_array($ch, $options); ==' . "\n";
|
|
|
|
|
|
|
|
// curl handler
|
|
|
|
$ch = curl_init();
|
|
|
|
|
|
|
|
// options for the curl handler
|
|
|
|
$options = array (
|
|
|
|
CURLOPT_URL => $url,
|
|
|
|
CURLOPT_RETURNTRANSFER => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
ob_start(); // start output buffering
|
|
|
|
|
|
|
|
curl_setopt_array($ch, $options);
|
|
|
|
$returnContent = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
var_dump($returnContent);
|
|
|
|
|
|
|
|
?>
|
|
|
|
--EXPECT--
|
|
|
|
== Starting test curl_setopt_array($ch, $options); ==
|
|
|
|
string(25) "Hello World!
|
|
|
|
Hello World!"
|
|
|
|
|