php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58571 pecl_http doesn't save correctly on cookiestore
Submitted: 2009-03-02 11:19 UTC Modified: 2010-04-28 02:44 UTC
From: xmorueco at gmail dot com Assigned: mike (profile)
Status: No Feedback Package: pecl_http (PECL)
PHP Version: 5.2.0 OS: Linux Debian
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-03-02 11:19 UTC] xmorueco at gmail dot com
Description:
------------
When you set cookiestore as Request Options, when finally pecl_http try to open file specified on cookiestore, it try to open an incorrect path file. 
You can see strace/truss:
It seems that can open file for reading, but fails when try to open to save cookie results.
READ:
open("cookies/e58b84332af6bd90b4a1df39a1a4be3a", O_RDONLY|O_LARGEFILE) = 4
WRITE:
open("", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = -1 ENOENT (No such file or directory)

It's works correctly in pecl_http-1.6.0, but fails in pecl_http-1.6.3 and now in pecl_http-1.7.0b1

Reproduce code:
---------------
$url=$argv[1]; // URL to check login
$postinfo=$argv[2]; // POST info: user_name=demo:password=demo
$cookiesDir='cookies/'; // Directory to save cookies

$requestOptions = array
(
'timeout'       => 10,
'redirect'      => 10,
'useragent'     => 'Mozilla/4.0',
'cookiestore'   => "$cookiesDir".md5($url)
);

$post=explode(":",$postinfo);
foreach ($post as $param) {
        $value=explode("=",$param);
        $postData[$value[0]]=$value[1];
}

$response = http_post_fields("http://$url", $httppostData, NULL, $requestOptions, $info);

Expected result:
----------------
pecl_http-1.6.0
READ:
open("cookies/e58b84332af6bd90b4a1df39a1a4be3a", O_RDONLY|O_LARGEFILE) = 4
WRITE:
open("cookies/e58b84332af6bd90b4a1df39a1a4be3a", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 0

Actual result:
--------------
pecl_http-1.6.3
READ:
open("cookies/e58b84332af6bd90b4a1df39a1a4be3a", O_RDONLY|O_LARGEFILE) = 4
WRITE:
open("", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = -1 ENOENT (No such file or directory)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-17 07:09 UTC] mike@php.net
Could you try this version please:
http://dev.iworks.at/ext-http/pecl_http-1.6.4dev.tgz
 [2009-03-19 16:18 UTC] xmorueco at gmail dot com
This version has the same problem.

Steps:
1. Uninstall version 1.6.0
pecl uninstall pecl_http-1.6.0


2. Install new dev version:
cd /usr/local/src
wget http://dev.iworks.at/ext-http/pecl_http-1.6.4dev.tgz
tar -xvzf pecl_http-1.6.4dev.tgz
cd pecl_http-1.6.4dev
phpize
./configure
make
make install

3. Test script to check if cookie is saved correctly in the directory
(strace captured with: strace -eopen)
open("./http_login.php", O_RDONLY|O_LARGEFILE) = 3
open("cookies/c44bc79e1848e947ad518e4434eeb360", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/etc/resolv.conf", O_RDONLY)      = 3
open("/etc/hosts", O_RDONLY)            = 3
open("/etc/hosts", O_RDONLY)            = 3
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib/tls/i686/cmov/libnss_dns.so.2", O_RDONLY) = 3
3.138643
open("", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = -1 ENOENT (No such file or directory)
Process 4312 detached

The problem persist as we can see in the last line.

4. Install version 1.6.0:
pecl install pecl_http-1.6.0

5. Results with the same test
open("./http_login.php", O_RDONLY|O_LARGEFILE) = 3
open("cookies/c44bc79e1848e947ad518e4434eeb360", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/etc/resolv.conf", O_RDONLY)      = 3
open("/etc/hosts", O_RDONLY)            = 3
open("/etc/hosts", O_RDONLY)            = 3
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib/tls/i686/cmov/libnss_dns.so.2", O_RDONLY) = 3
0.644686
open("cookies/c44bc79e1848e947ad518e4434eeb360", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 0
Process 13687 detached

If you need something more to try, don't doubt to let me know.
 [2009-12-30 04:26 UTC] mike@php.net
Thank you for taking the time to report a problem with the package.
Unfortunately you are not using a current version of the package -- 
the problem might already be fixed. Please download a new
version from http://pecl.php.net/packages.php

If you are able to reproduce the bug with one of the latest
versions, please change the package version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PECL.

.
 [2009-12-30 04:26 UTC] mike@php.net
Doh, this should have been marked with status = Feedback.
 [2010-03-25 13:59 UTC] joseph dot stelmach at csqauredsystems dot com
I am running into the same issue on Ubuntu Server 9.10, PHP 5.2.10 and using the latest pecl_http package ( 1.7.0b2 ).  I have no issue on windows however.

We're defining our options like this:

    $POST_OPTIONS = array(
            'httpauth'=>"$username:$password",
            'httpauthtype'=>HTTP_AUTH_BASIC,
            'timeout'=>'300',
            'connecttimeout'=>'20',
            'redirect'=>'3',
            'cookiestore'=>COOKIE_FILE
    );

Where COOKIE_FILE = /tmp/cook.tmp

After running:

 $page1 = http_post_data($CSI_URL, null, $POST_OPTIONS);

Nothing is added to the cook.tmp file.
 [2010-03-25 14:38 UTC] joseph dot stelmach at csquaredsystems dot com
Sorry, typo in my original email address...
 [2010-04-28 02:44 UTC] mike@php.net
See the 'Persistent handles and "cookiestore" request option' section here: http://svn.php.net/viewvc/pecl/http/trunk/KnownIssues.txt?view=markup
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC