php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22517 CURL does not work using curl_setopt($curl, CURLOPT_FILE, $fp);
Submitted: 2003-03-03 06:53 UTC Modified: 2003-03-14 12:02 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jacques@php.net Assigned:
Status: Closed Package: cURL related
PHP Version: 4.3.0/4.3.1/4.3.2-dev OS: FreeBSD 4.7-(STABLE|RELEASE)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jacques@php.net
New email:
PHP Version: OS:

 

 [2003-03-03 06:53 UTC] jacques@php.net
Hi,

I've written some ISP management software some time ago, and I've upgraded two servers at home in preparation for a roll out on our production servers, to test all our PHP code works.

Some of my scripts work via the CLI other work via the mod_php version on apache 1.3.26 / 1.3.27 versions of apache.  OpenSSL versions 0.9.6g and 0.9.7 have been tested.

On php 4.2.3 with curl version's 7.9.8 and 7.10.3 I do not get this problem.  On 4.3.0 and 4.3.1 I have this error where (a) I don't get anything data in the $fp file descriptor and (b) it's moans about the following:

===
root@mimbari:/usr/local/vweb/stats.ataris.co.za/data/cacti/scripts# php uudial.php
* About to connect() to waggle.ops.uunet.co.za:443
* Connected to waggle.ops.uunet.co.za (196.7.0.184) port 443
* SSL: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
* Closing connection #0
SSL: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Array
(
    [data] =>
    [http_code] => 0
)
Cannot get UUnet Session ID
===

Tried using the following CURL SETOPT's:
 * CURLOPT_SSL_VERIFYPEER
 * CURLOPT_SSLVERSION
 * CURLOPT_SSL_VERIFYHOST

Snipbit from my UUdial class function getSecureCookie.

$fp = tmpfile();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $uunet_url);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_USERPWD, $uunet['login']);
curl_setopt($curl, CURLOPT_PROXY, "http://192.168.10.254:3128/");
curl_exec($curl);

$response['http_code'] = curl_getinfo($curl, CURLINFO_HTTP_CODE); /* This is used to see if we get a HTTP 200 code */

rewind($fp);
while ($str = fgets($fp, 4096)) {
	$pairs .= $str;
}
fclose($fp);

$response['data'] = $pairs;
asort($response);

if ($response['http_code'] == "200") {
	preg_match ('/<frame src=".*?auth_cookie=([\w]+:[\w]+)">/ims', $response['data'], $n);
	if ($n[1]) {
		$this->cookie = $n[1];
	} else {
		die ("Cannot get UUnet Secure Cookie");
	}
} else {
	die ("Cannot get UUnet Secure Cookie");
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-03 13:35 UTC] jacques@php.net
Busy building the latest stable which I downloaded earlier today.  Will keep you guys posted on the status.
 [2003-03-03 14:46 UTC] jacques@php.net
Still same problems with the latest php4 STABLE which I downloaded this afternoon.

root@mimbari:/usr/local/src/php4-STABLE-200303031230/sapi/cli# ./php -v
PHP 4.3.2-dev (cli) (built: Mar  3 2003 21:54:28)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
    with Zend Optimizer v2.1.0, Copyright (c) 1998-2003, by Zend Technologies
 [2003-03-03 17:13 UTC] daniel at haxx dot se
http://curl.haxx.se/docs/sslcerts.html
 [2003-03-03 17:18 UTC] edink@php.net
Not a PHP bug but a feature of the new version of libcurl.

As Daniel pointed out have a look at:

http://curl.haxx.se/docs/sslcerts.html
 [2003-03-03 19:02 UTC] jacques@php.net
Apart from (b) with the SSL stuff, part (a) where $fp does not get anything from the CURL session for example if I do something like following, $fp does not get any data using the CURLOPT_FILE setopt setting:

<?php
$saix_url = "http://isp.saix.net/cgi-bin/ISPUserHistory.pl";

$fp = tmpfile();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $saix_url);
curl_setopt($curl, CURLOPT_TIMEOUT, 2000);
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_USERPWD, $saix['login']);
curl_setopt($curl, CURLOPT_PROXY, "http://192.168.253.14:3128/");
curl_exec($curl);
curl_close($curl);

Adding the following option and adding a $get_ouptut_since_fp_contains_no_data = in front of the curl_exec call seems to get the data that $fp should have contained.

$fp = tmpfile();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $saix_url);
curl_setopt($curl, CURLOPT_TIMEOUT, 2000);
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_USERPWD, $saix['login']);
curl_setopt($curl, CURLOPT_PROXY, "http://192.168.253.14:3128/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$get_output_since_fp_contains_no_data = curl_exec($curl);
curl_close($curl);

...

I'm going to play around with the curl extension and see if I can come up with a patch to fix the CURLOPT_FILE stuff.
 [2003-03-14 12:02 UTC] jacques@php.net
I've developed a quick test using the http://www.php.net/mirror-test.php

jacques@phantom:/tmp$ php -q test.curlfpisbroken.php
Array
(
)
jacques@phantom:/tmp$ php -v
4.2.1
jacques@phantom:/tmp$ cat test.curlfpisbroken.php
<?php
// +----------------------------------------------------------------------+
// | PHP version 4.0                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Jacques Marneweck <jacques@php.net>                         |
// +----------------------------------------------------------------------+//
// $Id:$

/* Test for php4 to prove that CURLOPT_FILE is broken in PHP 4.3.x including
 * the 4.3.2-dev (PHP Bug #22517)
 */

$php_url = "http://www.php.net/mirror-info.php";

$fp = tmpfile();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $php_url);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_FILE, $fp);
#curl_setopt($curl, CURLOPT_PROXY, "http://192.168.254.14:3128/");
curl_exec($curl);

$response['http_code'] = curl_getinfo($curl, CURLINFO_HTTP_CODE);

rewind($fp);
while ($str = fgets($fp, 4096)) {
        $pairs .= $str;
}
fclose($fp);

$response['data'] = $pairs;
asort($response);

$expecteddata = explode ("|", "http://www.php.net/|4.3.0-dev|1047661845|1|2|en");
$datawehave = explode ("|", $response['data']);

$diff = array_diff ($expecteddata, $datawehave);

print_r ($diff);
?>
Okay it the CURLOPT_FILE works nicely on php 4.2.1 :)

Now testing 4.3.0:
Array
(
    [0] => http://www.php.net/
    [1] => 4.3.0-dev
    [2] => 1047661845
    [3] => 1
    [4] => 2
    [5] => en
)
root@mimbari:~/test# php -v
PHP 4.3.0 (cli) (built: Feb 19 2003 13:51:54)
Copyright (c) 1997-2002 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies
    with Zend Optimizer v2.1.0, Copyright (c) 1998-2003, by Zend Technologies

Now going to test the latest stable build:
Looks like Ilia Alshanetsky's patch to ext/curl/interface.c yesterday fixes my issues :)

su-2.05b# ./php -v
PHP 4.3.2-RC (cli) (built: Mar 14 2003 19:43:26)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
    with Zend Optimizer v2.1.0, Copyright (c) 1998-2003, by Zend Technologies
su-2.05b# ./php -q test.curlfpisborken.php
Array
(
)

Thanks Ilia Alshanetsky :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 16:01:33 2024 UTC