Contact Us

Windows XP Apache PHP output problem

Posted on 3/11/06 by Felix Geisendörfer

... those were (some of) the google keywords I used to search for a solution to the Heisenbug that recently killed my productivity. Big thanks to meek, who has found the bug in Windows XP (no SP) that caused the problem:

Q317949: Socket Sharing Creates Data Loss When Listen and Accept Occur on Different Processes

I'm doing this post because I hope that Google will index it, and the next person hitting the issue will find my blog this way, so he doesn't have to go through the same issues that had to deal with.

So in case your system has the following SYMPTOMS, please have a look at the steps below that helped me fixing the issue.

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.

Or with other words: Files served via php's output functions like fread, fpassthrough, readfile, imagejpg and so on will not completly be recieved by the browser causing incomplete & often disturbed display of the data.

The solution is quite simple, one can either update to the latest Service pack, or if that is problematic (because the SP is incompatible with one's hardware like in my case), one can simply replace the \Windows\system32\drivers\afd.sys with a newer version. So if you want to use the second option, here is what you have to do:

  1. Backup your existing \Windows\system32\drivers\afd.sys. In case something goes wrong you sure want to be able to fix it.
  2. Disable Windows automatic System restore functionality. Go to Start->Run->[type in 'control', then hit enter]->System. Select the System Recovery tab and check the box to deactive the functionality. Then hit Ok.
  3. Download a SP2 version of the afd.sys. (Thanks to my friend Robert H. for sending me his copy!)
  4. Copy this file to \Windows\system32\drivers and \Windows\system32\dllcache and overwrite the existing versions of the file. If Windows starts to bug you to insert the Windows XP CD, ignore it as you usually do with useless error messages ; ).
  5. Restart your System
  6. Check that the afd.sys in \Windows\system32\drivers is the one you downloaded and has not been replaced with the old one (you can use modified date, file size, md5 hash, version, or whatever suits you best to do this).
  7. Check if the problem still exists. If no, donate all your money to "Felix Geisendörfer" via Paypal ; ). (Just kidding)

Oh boy, this has been a true nightmare and I really want to thank all the people who have thrown in their suggestions in the Google Group post and the blog post I made. Now I can finally go back to being productive!

And for those of you wondering why I'm on Windows and don't switch to some *Nix system like all the cool kids: I like Windows. Don't get me wrong, there is an endless list of things I truly hate about it, and an even more endless list of reasons why I don't like Microsoft, but in reality it's the OS that runs all the Apps I love, that I know the best and that has the best GUI (to me). There are a lot of things I like about Mac OS X & Linux, and I will eventually start using one of them as a second OS at some point, but there are just too many drawbacks for me right now. Robert Nyman has a nice post highlighting some things about OS X that suck and I got quite a couple others in my head as well. But again, the truth simply is that me using Windows is a marriage of convenience. Nothing more and nothing less ; ).

--Felix Geisendörfer aka the_undefined


You can skip to the end and add a comment.

Dieter@be  said on Nov 03, 2006:

Congratulations Felix :)

I suppose that by "productive" you actually mean working on all the goodies that we like, right? :-D
like the deployment script for cake 1.2, cake 1.2 itself , the bakery (after all, you're a "big kitchen" baker now ;-))

Also, updating windows is one of the first things one should do if having trouble. Offcourse if it doesn't work with your hardware (really sure about that? mickeysoft can tell you anything they want) it makes it all a bit harder...
probably the main reason why not many others have the same problems.

meek said on Nov 03, 2006:

Phew, that's a relief.
The search terms I used were: 'apache output corrupt jpg'. Still only got something half relevant on the second page. Very obscure!

Grüsse aus Berlin!

Felix Geisendörfer said on Nov 03, 2006:

Hey meek: Well I always included php in my search because I didn't have issues with serving the file via apache directly. I also tried the corrupted keyword a couple times, but no luck.

Anyway, thanks a lot for pointing me in the right direction, I just linked your name in the post above to the web site you provided in your comment as a little traffic thank you ; ).

Viele Grüße aus Zwickau nach Berlin von mir ; ).

[...] First of all: Yeahhh, today has been my first really productive day since I've overcome my recent issues, lot's of things got done and I'm exited to have even found time to write a little post on my blog here ; ). [...]

Windows said on Feb 02, 2007:

Windows, the path of least resistance?

It is for myself... And considering that most of the popular Linux apps, like Apache, have stable win32 ports, it could be for you too.

bart simpson  said on May 04, 2007:

query: xampp apache garbage file corrupt ? Update afd.sys !

I send it to xampp guys. Apache works fine but spits garbage without updating
I found your advice extremely helpful and my apache is happy now. Thanks

(mostl use old pc to run xampp, and soho web servers are virtualized machines
so they dont update often. They refresh the snapshot and that's it.

So this apache / php corruption would continue ad infinitum on virtualized machines.
without updating afd.sys.

note for Admin: remove the previous depressing spam posts
as they downgrade your google rating. You shoud be top rated for this thing!

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.