OT: Heisenbug with binary data output in PHP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

OT: Heisenbug with binary data output in PHP

the_undefined
Hi,

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 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);

header('Content-Type: image/jpeg');
header('Content-Length: '.$fileSize);
      
$fp = fopen($pictureFile, 'rb');
fpassthru($fp);
fclose($fp);
--------------------------------------------------------------------------------------------------------

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 ... : /.

And again, sorry for this being off topic but I'm pretty desperate.
Felix Geisendörfer aka the_undefined

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Dr. Tarique Sani <tarique@sanisoft.com>

Can you give the URL of the offending image? I will try and look into
it

Cheers
Tarique


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

the_undefined
Hi,

http://www.thinkingphp.org/133.jpg would be a direct link to one of the images I test with, however all pictures I tried behave the same way.
http://www.thinkingphp.org/image.php (source can be found at http://www.thinkingphp.org/image.phps) would be a script that runs fine on my host (serving 133.jpg), but causes the Heisenbug on my system.

Thanks for your interest!

Felix


Dr. Tarique Sani [hidden email] schrieb:
Can you give the URL of the offending image? I will try and look into
it

Cheers
Tarique




  

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Bert Van den Brande
In reply to this post by Dr. Tarique Sani <tarique@sanisoft.com>

Did you try it with different browsers ?

Since it works fine on you webhost I'm guessing this is a weird
windows related problem, so those service packs might not be a bad
idea ...

Do you have a virus scanner or something ? Maybe the scanner has
problems with Apache or Php ...

This is by far one of the weirdest php-related problems I've heard of :)

On 11/3/06, Dr. Tarique Sani <[hidden email]> <[hidden email]> wrote:

>
> Can you give the URL of the offending image? I will try and look into
> it
>
> Cheers
> Tarique
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

the_undefined
Hi Bert,

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.

Best Regards,
Felix Geisendörfer


Bert Van den Brande schrieb:
Did you try it with different browsers ?

Since it works fine on you webhost I'm guessing this is a weird
windows related problem, so those service packs might not be a bad
idea ...

Do you have a virus scanner or something ? Maybe the scanner has
problems with Apache or Php ...

This is by far one of the weirdest php-related problems I've heard of :)

On 11/3/06, Dr. Tarique Sani [hidden email] [hidden email] wrote:
  
Can you give the URL of the offending image? I will try and look into
it

Cheers
Tarique


    



  

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Bert Van den Brande

Have you tried reading the image with a buffer in php ?

On 11/3/06, Felix Geisendörfer <[hidden email]> wrote:

>
>
>  Hi Bert,
>
>  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.
>
>  Best Regards,
>  Felix Geisendörfer
>
> --------------------------
>  http://www.thinkingphp.org
>  http://www.fg-webdesign.de
>
>  Bert Van den Brande schrieb:
>  Did you try it with different browsers ?
>
> Since it works fine on you webhost I'm guessing this is a weird
> windows related problem, so those service packs might not be a bad
> idea ...
>
> Do you have a virus scanner or something ? Maybe the scanner has
> problems with Apache or Php ...
>
> This is by far one of the weirdest php-related problems I've heard of :)
>
> On 11/3/06, Dr. Tarique Sani <[hidden email]> <[hidden email]>
> wrote:
>
>
>  Can you give the URL of the offending image? I will try and look into
> it
>
> Cheers
> Tarique
>
>
>
>
>
>
>
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Gustavo Carreno
In reply to this post by the_undefined

Hey Felix,

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 >

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Meek-2

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?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Meek-2

Also maybe a screenshot of what you get - and do you have the same
problem with other filetypes like a .png for example?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Meek-2

I found a couple of things which might be relevant:

The section 'Problems Installing or Running Apache 2' on this page:

http://www.apache.org/dist/httpd/binaries/win32/README.html

- which I got to from this:

http://marc2.theaimsgroup.com/?l=apache-bugdb&m=101484400413021&w=2


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

the_undefined
Hey meek,

I think you found the exact bug. It's Microsoft to blame: http://support.microsoft.com/default.aspx?scid=kb;en-us;317949

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

<script type="text/javascript">loadTOCNode(1, 'resolution');</script>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 ...

--Felix Geisendörfer aka the_undefined


meek schrieb:
I found a couple of things which might be relevant:

The section 'Problems Installing or Running Apache 2' on this page:

http://www.apache.org/dist/httpd/binaries/win32/README.html

- which I got to from this:

http://marc2.theaimsgroup.com/?l=apache-bugdb&m=101484400413021&w=2




  

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

Bert Van den Brande

Good to know, seems our educated guess that this was a Windows problem
was completely correct :)

On 11/3/06, Felix Geisendörfer <[hidden email]> wrote:

>
>  Hey meek,
>
>  I think you found the exact bug. It's Microsoft to blame:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;317949
>
>
>
> 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 ...
>
>  --Felix Geisendörfer aka the_undefined
>
> --------------------------
>  http://www.thinkingphp.org
>  http://www.fg-webdesign.de
>
>  meek schrieb:
>  I found a couple of things which might be relevant:
>
> The section 'Problems Installing or Running Apache 2' on this page:
>
> http://www.apache.org/dist/httpd/binaries/win32/README.html
>
> - which I got to from this:
>
> http://marc2.theaimsgroup.com/?l=apache-bugdb&m=101484400413021&w=2
>
>
>
>
>
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: OT: Heisenbug with binary data output in PHP

the_undefined
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!

In order to save others from having this nightmare in future I did a little blog post that describes the symptoms I had together with the solution that helped me.

--Felix Geisendörfer aka the_undefined


Bert Van den Brande schrieb:
Good to know, seems our educated guess that this was a Windows problem
was completely correct :)

On 11/3/06, Felix Geisendörfer [hidden email] wrote:
  
 Hey meek,

 I think you found the exact bug. It's Microsoft to blame:
http://support.microsoft.com/default.aspx?scid=kb;en-us;317949



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 ...

 --Felix Geisendörfer aka the_undefined

--------------------------
 http://www.thinkingphp.org
 http://www.fg-webdesign.de

 meek schrieb:
 I found a couple of things which might be relevant:

The section 'Problems Installing or Running Apache 2' on this page:

http://www.apache.org/dist/httpd/binaries/win32/README.html

- which I got to from this:

http://marc2.theaimsgroup.com/?l=apache-bugdb&m=101484400413021&w=2






 >

    



  

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---