From: jdespatis at yahoo dot fr Operating system: Linux Kubuntu PHP version: 5.2.6 PHP Bug Type: Streams related Bug description: stream_context_create creates bad http request
Description: ------------ I'm coding a little script to upload a video on Youtube, thanks to stream functions in php. It takes 2 steps: 1/ first connect on google to retrieve token, no problem with php code 2/ upload video with a query in POST, and there stream_context_create is giving a completely broken query.. From time to time, i can make it work, but it's pure random I have used a sniffer as wireshark to see the exact http query Reproduce code: --------------- Here is the piece of code that does all this stuff: http://www.despatis.com/php/bug.phps Expected result: ---------------- PHP CLIENT => YOUTUBE SERVER: POST /feeds/api/users/bigbluezen/uploads HTTP/1.0 Host: uploads.gdata.youtube.com Content-Length: 792 Content-Type: multipart/related; boundary="---------------------------cefe168b3cb99683a0f9ebd6f9b2cca6" Authorization: GoogleLogin auth=AIwbFAQtr5MDW_ctllHioiYCpY6I_uF6A9zBcSbIQ8AceGbcYfqrmytEICM8p6VjjzygDd2HPL0YhTcVk2MPmtb9y93-9Fs3yiej8hBtLF60_N_a6aWDg9Mrbm18nP-2dTVvTA6h77eJZrOJICzgN3dZyPT4AN1ffQ X-GData-Client: ytapi-SourceRH-LaCartoonerie-3lludu8g-0 X-GData-Key: key=AI39si44WZavBNwYryVhVFaMH4Y8e0JbTAr83bScAxKby6LBW3xEyBzaXrV7MTw3sm56SmYVhSOWRXNfUrS0sqC1i7313ycFrQ Slug: c447e7c1c0b79e8dc97c76cdc16e9843.gif -----------------------------cefe168b3cb99683a0f9ebd6f9b2cca6 Content-Type: application/atom+xml; charset=UTF-8 <?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <media:group> <media:title type="plain">title foo</media:title> <media:description type="plain">description foo</media:description> <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category> <media:keywords>key1, key2</media:keywords> </media:group> </entry> -----------------------------cefe168b3cb99683a0f9ebd6f9b2cca6 Content-Type: video/gif Content-Transfer-Encoding: binary XXX -----------------------------cefe168b3cb99683a0f9ebd6f9b2cca6-- Actual result: -------------- The actual result, found with a sniffer (wireshark for example) is: PHP CLIENT => YOUTUBE SERVER: POST /feeds/api/users/bigbluezen/uploads/wFqcFtuB9MY?client=ytapi-SourceRH-LaCartoonerie-3lludu8g-0 HTTP/1.0 Host: gdata.youtube.com Authorization: GoogleLogin auth=AIwbFASurkAdrgigXGJeP24Ebc0dM7EierouUTZ7Nqm2pjSzo2aRtNXQgOo-_ebco_-w7CmpxcZqysZKS_UGCUSc-K6tD5NI84jIc7sf1Sq8cPtcbknOrvlqxF6PNBj-kLzeXEPnBwKoE4vJDuwE0ag7Aleyo-u3hw X-GData-Client: ytapi-SourceRH-LaCartoonerie-3lludu8g-0 X-GData-Key: key=AI39si44WZavBNwYryVhVFaMH4Y8e0JbTAr83bScAxKby6LBW3xEyBzaXrV7MTw3sm56SmYVhSOWRXNfUrS0sqC1i7313ycFrQ Slug: c447e7c1c0b79e8dc97c76cdc16e9843.gifbScAxKby6LBW3xEyBzaXrV7MTw3sm56SmYVhSOWRXNfUrS0sqC1i7313ycFrQ Slug: c447e7c1c0b79e8dc97c76cdc16e9843.gif EOF As you can see, the first query is completely messy !! The funny thing is that: if i change '<?xml version="1.0"?>' to '<xml version="1.0">' at line 64, the http query is good... One could thing <? is interpreted by php, but in fact no... it also works if i keep the <? and ?> in the xml and change another things (add an echo somewhere, but this trick doesn't work all the time) As the result is very random, i think file_get_contents doesn't get all data from the string, leaving some \r\n, which mess the following http query, maybe something like that... -- Edit bug report at http://bugs.php.net/?id=45540&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45540&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45540&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45540&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45540&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45540&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45540&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45540&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45540&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45540&r=support Expected behavior: http://bugs.php.net/fix.php?id=45540&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45540&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45540&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45540&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45540&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45540&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45540&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45540&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45540&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45540&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45540&r=mysqlcfg