File: curl_setopt_array_basic.phpt

package info (click to toggle)
php5 5.6.33%2Bdfsg-0%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 157,872 kB
  • sloc: ansic: 756,065; php: 22,030; sh: 12,311; cpp: 8,771; xml: 6,179; yacc: 1,564; exp: 1,514; makefile: 1,467; pascal: 1,147; awk: 538; perl: 315; sql: 22
file content (57 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--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 include 'skipif.inc'; ?>
--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
include 'server.inc';
$host = curl_cli_server_start();
if (!empty($host)) {
    // 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);
isset($tempname) and is_file($tempname) and @unlink($tempname);

?>
--EXPECT--
== Starting test curl_setopt_array($ch, $options); ==
string(25) "Hello World!
Hello World!"