ID: 49611 Updated by: j...@php.net Reported By: d dot reade at readesresidential dot com -Status: Open +Status: Feedback Bug Type: Filesystem function related Operating System: CentOS 5.3 x86 PHP Version: 5.2.11 New Comment:
I can not reproduce this. Please provide the full script that causes this, including the $url.. Previous Comments: ------------------------------------------------------------------------ [2009-09-21 08:11:21] d dot reade at readesresidential dot com I have managed to replicate the issue, multiple times. Here's the code: <? $array = array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1); foreach($array as $val) { $tmp = tempnam('/tmp', 'test_img_'); $file = file_get_contents($url); file_put_contents($tmp, $file); $img = imagecreatefrompng($tmp); imagedestroy($img); } ?> In my case $url was the direct http:// path to the image, in this instance a high quality PNG over 1MB in size. The script repeats 80 times (to mimic what my scripts are trying to do). After the first run it stated 15 out of 80 of the PNGs were invalid PNG files. On the second run it said 12 were invalid. The results are different each time. The error generated by PHP is: Warning: imagecreatefrompng() [function.imagecreatefrompng]: '/tmp/test_img_92M2J2' is not a valid PNG file in /home/readesre/public_html/dev/img.php on line 12 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/readesre/public_html/dev/img.php on line 14 Here's the list of files from the tmp folder: -rw------- 1 nobody nobody 1778247 Sep 21 09:01 test_img_92M2J2 -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_bHZKlf -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_btMJcI -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_DctHCw -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_dnosxg -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_DOZKw1 -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_DxQcqp -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_f95art -rw------- 1 nobody nobody 1778247 Sep 21 09:01 test_img_H5SukI -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_LcT3ss -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_lkEMhQ -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_lucjnA -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_nksxx7 -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_To6cXV -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_vEzSrY -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_vqmVzZ -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_x8cIzF -rw------- 1 nobody nobody 1778247 Sep 21 09:01 test_img_XzAwHt -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_ZA0s5W -rw------- 1 nobody nobody 1778247 Sep 21 09:01 test_img_ZgkSty -rw------- 1 nobody nobody 1777966 Sep 21 09:01 test_img_zVa5gj This is only a snippet of the full list, but notice the file sizes. The files that are 1778247 in size contain the following header info: HTTP/1.1 200 OK Date: Mon, 21 Sep 2009 08:01:24 GMT Server: Apache Last-Modified: Fri, 18 Sep 2009 10:26:04 GMT Accept-Ranges: bytes Content-Length: 1777966 Cache-Control: max-age=2592000 Expires: Wed, 21 Oct 2009 08:01:24 GMT Connection: close Content-Type: image/png �PNG Followed by the rest of the PNG file... ------------------------------------------------------------------------ [2009-09-20 23:03:15] ras...@php.net It would be really helpful if you could create an actual script that reproduces this. It isn't until the 8th comment on this bug that we learn that it only happens if you are doing a whole bunch of them together. Your original reproducing script not only didn't have any network component, but it also didn't have anything about multiple connections. How are you doing these multiple connections? Just a big loop around file_get_contents? The best way to report a bug is to simplify your problem down into a script that we can run ourselves and see the problem. If we can see it, we can fix it. Otherwise we are guessing as to what might be happening on your end. ------------------------------------------------------------------------ [2009-09-20 22:44:06] paj...@php.net I was thinking about a bug the curl stream wrapper, but no. I can't reproduce this problem either, no matter the web server/OS/platform. ------------------------------------------------------------------------ [2009-09-20 22:21:10] d dot reade at readesresidential dot com Sure, here it is: './configure' '--disable-pdo' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-sockets' '--enable-zip' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-freetype-dir=/usr' '--with-gd' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-png-dir=/usr' '--with-t1lib=/usr' '--with-ttf' '--with-xpm-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr' ------------------------------------------------------------------------ [2009-09-20 22:19:25] paj...@php.net Can you show us your configure line too please? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/49611 -- Edit this bug report at http://bugs.php.net/?id=49611&edit=1