function checkForClosedFilePointer($curl_option, $description)
{
    $fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
    $ch1 = curl_init();
    $ch2 = curl_init();
    $options = array(CURLOPT_RETURNTRANSFER => 1, $curl_option => $fp, CURLOPT_URL => curl_cli_server_start());
    // we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly
    if (CURLOPT_STDERR == $curl_option) {
        $options[CURLOPT_VERBOSE] = 1;
    }
    if (CURLOPT_INFILE == $curl_option) {
        $options[CURLOPT_UPLOAD] = 1;
    }
    curl_setopt_array($ch1, $options);
    curl_setopt_array($ch2, $options);
    fclose($fp);
    // <-- premature close of $fp caused a crash!
    $mh = curl_multi_init();
    curl_multi_add_handle($mh, $ch1);
    curl_multi_add_handle($mh, $ch2);
    $active = 0;
    do {
        curl_multi_exec($mh, $active);
    } while ($active > 0);
    curl_multi_remove_handle($mh, $ch1);
    curl_multi_remove_handle($mh, $ch2);
    curl_multi_close($mh);
    echo "Ok for {$description}\n";
}
<?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);
Example #3
0
<?php

include 'server.inc';
$fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
curl_setopt($ch, CURLOPT_URL, curl_cli_server_start());
fclose($fp);
// <-- premature close of $fp caused a crash!
curl_exec($ch);
curl_close($ch);
echo "Ok\n";
error_reporting(0);
@unlink(dirname(__FILE__) . '/bug48203.tmp');