first of all, this problem has been stopping me from making any progress with my CakePHP application for 2 days by now, but as far as I can tell it's a general PHP problem (means it occurs in a standalone script as well). However, since I know there are some very smart & experienced php folks on this group I hope somebody might be able to help me out on this one anyway. (I also suspect the issue is not related to my code but to my local setup).
So the problem is the following: I want to use a Controller to serve jpg images stored outside the webroot folder to the visitors of the site I'm working on. Essentially I just want to use PHP to output the contents of a file to the browser. This should be the easiest thing in the world, but I'm experiencing a Heisenbug <http://en.wikipedia.org/wiki/Heisenbug> where in some cases not the entire image is displayed but rather only the top part of it and the rest is either left blank or (partially) covered with random patterns (like when a DivX encoded video turns bad and some frames have lot's of green or such in them). This happens with all pictures I use, even so if I put those images in the webroot they display just fine. And as I said, sometimes (25-33%) the bug does not occur at all and there is no problem (therefor I call it a Heisenbug).
The code I use looks like this: --------------------------------------------------------------------------- ----------------------------- $pictureFile = Picture::getPath($picture); $fileSize = filesize($pictureFile);
Now I tried various things to fix this. I used a loop to output the image. I used readfile. I used echo file_get_contents(), I used ob_flush() and flush() but nothing seemed to have any effect. One thing that seemed to slightly decrease the problem (more of the image get's displayed) was to put usleep() function calls inside a loop that's echo & fread'ing the picture. Adding an echo "Hello"; statement at the end of the function and turning off the image/jpeg header (and thus looking at the raw output) unveiled that the problem is definitely caused by parts of the output getting lost. Because the length of the output varied and most of the times the "Hello" at then end was missing.
Being on the edge of going insane I also uploaded the script to my web host to see if this behavior would also exist on other platforms - it does not! So chances are there is something wrong with my local setup, and the php code is just fine. Here is what I'm currently running on:
Windows XP - no service pack (got a legitimate copy, but their patches seem to be incompatible with my hardware ...) PHP 4.4.1 (that's what runs on my web host, I just updated to it from 4.4.0 to make sure the bug is not due to my old version) Apache 2.0.55
I already checked douzens of php.ini options related to output buffering, memory limits, and such things, but no success. Oh and another very important point is that my script executes completely, even if output get's lost. I checked this by saving the contents of the image file into a variable, dumping the variable content and then saving it to a new file. The resulting image file displayed just fine, the dumped variable content produced the Heisenbug that gives me headaches ...
Alright, I'm close to either killing myself or to reconfigure my entire development environment, so if anybody has the slightest idea what could be going on here, please let me know. The last days have been bad already since one of my SVN repositories went bad (and was unrecoverable) and now this ... Time for a vacation I guess ... : /.
I can't get the service packs, they are incompatible with my hardware. I spent 12 hours at a LAN party once trying to get them on my machine and besides loosing data, cursing a lot and seeing more blue screens of death then I thought WinXP to have I decided to not ever try this again.
I tried it with different browser (FF 1.5, IE 6, Opera 9) and they all show the same / similar behavior.
Turning of my virus scanner is something I haven't tried yet. I'll do that together with the firewall, but I can't see why either one of them would randomly swallow the last packages of pictures provided via php ... I'll let you know what happens.
> I can't get the service packs, they are incompatible with my hardware. I > spent 12 hours at a LAN party once trying to get them on my machine and > besides loosing data, cursing a lot and seeing more blue screens of death > then I thought WinXP to have I decided to not ever try this again.
> I tried it with different browser (FF 1.5, IE 6, Opera 9) and they all show > the same / similar behavior.
> Turning of my virus scanner is something I haven't tried yet. I'll do that > together with the firewall, but I can't see why either one of them would > randomly swallow the last packages of pictures provided via php ... I'll let > you know what happens.
Just remembered something, have you tryed with the GD functions yet? I know it could a bit more work since you are not doing any image manipulation, but could you try and use ImageJPG/GIF/PNG to output your images, just to exclude a general output problem and focusing on the fread, fpassthru problem ?
-- Gustavo Carreno --- < If you know Red Hat you know Red Hat, If you know Slackware you know Linux >
Hi Felix, Maybe you could post your php.ini and httpd.conf. My development setup is very similar to yours and I can't reproduce the problem with your script and image. Couldn't have anything to do with your WLAN .jpg hack could it?
> Data loss may occur if all of the following conditions exist:
> * A bind of a listen socket is completed in a parent process. > * An accept is completed in a child process. > * Fast sends are happening.
This is exactly what I experience, and this explains why putting some usleep() statements in when outputting the image via a fread loop seems to have a positive effect (slows down the send process)!
However, I'm not sure if I like the solution:
> RESOLUTION
> To resolve this problem, obtain the latest service pack for Windows > XP. For additional information, click the following article number to > view the article in the Microsoft Knowledge Base:
The problem is that I have had a really bad time installing a service pack on my system in the past, but maybe that was because I tried to install from a different windows cd (I got an OEM version) with SP 2 instead of Downloading the patch (which is a bad option since I'm on 64 kbit) ...
Hmm but they a /Afd.sys/ file that seems to be problematic, maybe I can simply replace this with a SP 2 version. (Yeah, I know it's a bad idea ^^).
Thanks to all the others who have looked into this as well. I'll see if I can fix my system somehow without going through some major pain ...
> SYMPTOMS Data loss may occur if all of the following conditions exist:
> A bind of a listen socket is completed in a parent process. > An accept is completed in a child process. > Fast sends are happening. This is exactly what I experience, and this > explains why putting some usleep() statements in when outputting the image > via a fread loop seems to have a positive effect (slows down the send > process)!
> However, I'm not sure if I like the solution:
> RESOLUTION To resolve this problem, obtain the latest service pack for > Windows XP. For additional information, click the following article number > to view the article in the Microsoft Knowledge Base: > The problem is that I have had a really bad time installing a service pack > on my system in the past, but maybe that was because I tried to install from > a different windows cd (I got an OEM version) with SP 2 instead of > Downloading the patch (which is a bad option since I'm on 64 kbit) ...
> Hmm but they a Afd.sys file that seems to be problematic, maybe I can > simply replace this with a SP 2 version. (Yeah, I know it's a bad idea ^^).
> Thanks to all the others who have looked into this as well. I'll see if I > can fix my system somehow without going through some major pain ...
Ok, I resolved the issue by replacing my afd.sys with a newer version I got from a friend via email. Big thanks to everybody who has looked into the issue, especially meek!
>> SYMPTOMS Data loss may occur if all of the following conditions exist:
>> A bind of a listen socket is completed in a parent process. >> An accept is completed in a child process. >> Fast sends are happening. This is exactly what I experience, and this >> explains why putting some usleep() statements in when outputting the image >> via a fread loop seems to have a positive effect (slows down the send >> process)!
>> However, I'm not sure if I like the solution:
>> RESOLUTION To resolve this problem, obtain the latest service pack for >> Windows XP. For additional information, click the following article number >> to view the article in the Microsoft Knowledge Base: >> The problem is that I have had a really bad time installing a service pack >> on my system in the past, but maybe that was because I tried to install from >> a different windows cd (I got an OEM version) with SP 2 instead of >> Downloading the patch (which is a bad option since I'm on 64 kbit) ...
>> Hmm but they a Afd.sys file that seems to be problematic, maybe I can >> simply replace this with a SP 2 version. (Yeah, I know it's a bad idea ^^).
>> Thanks to all the others who have looked into this as well. I'll see if I >> can fix my system somehow without going through some major pain ...