Jump to content

Recommended Posts

I recently migrated from Windows XP to Windows 7, and a PHP package I depend on (mPDF, see http://www.mpdf1.com/mpdf) stopped working. When I call one of its necessary functions, it hangs.

 

I investigated further and found that the crash was happening in a call to file_get_contents, given one parameter, a URL that points to a CSS file.

 

I found that the file_get_contents and file functions both crash when given a URL. Both work normally when given a pathname on the local file system.

 

As I understand it, these functions are supposed to accept a URL if the INI directive allow_url_fopen is enabled. I checked by calling ini_get; it is. In any case, the php.net description of fopen says that if that directive is disabled, "PHP will emit a warning and the fopen call will fail" -- not just hang!

 

It appears as if there is a glaring bug in one of PHP's core functions. I'm very skeptical that that is really the problem, but I don't know what else to suspect. Any ideas?

 

My configuration is Windows 7 Professional with SP1; Apache 2.2.17; PHP 5.2.17.

 

For reference, here is the script I used to investigate this problem. I stepped through it with a debugger, so I didn't bother displaying results. As shown, the script works. When I comment out the second assignment to $path it should produce identical results; instead it hangs.

 

<?php
$isopen = ini_get('allow_url_fopen');
$path = "http://localhost/pdf/cert.css";
$path = "D:/htdocs/pdf/cert.css";
$contents = file($path);
$contents = @file($path);
$contents = file_get_contents($path);
$contents = @file_get_contents($path);
?>

I'm not sure what you mean by "go to." To me, in this context, "go to" means "load" (into the browser). When I load that URL into the browser it displays the contents of the file.

 

If I try to read the file from that URL in a script, it hangs, as I said. If I load an HTML page that refers to that location, it works normally. (The script actually loads an equivalent relative URL... if that's what you meant, and the difference between a relative and an absolute URL is significant, let me know, and I'll try it.)

Yes, when I run mPDF it hangs. (If it didn't I wouldn't be here, because I would not have a problem! :-) )

 

"Hang" means that the function never returns control to the script. Eventually the browser times out and I get an apparently complete page load with an empty display. There is no error message from PHP and no timeout from the server. If I'm running the debugger when I do this, I can't start the debugger again unless I restart both the IDE and the browser. That suggests that some part of each component has been left in an undefined state, but that doesn't suggest a possible cause to me.

 

I tried reading a remote page as you suggested, and it works. I tried reading a different local page and it hangs, so the problem appears to be associated with local URLs. That's progress, but I it doesn't suggest a possible cause either.

That works.

 

Very interesting... but not quite a solution, since mPDF derives the URL by adding http://localhost/subdirectory/ to a relative URL taken from a <style> tag.

 

For the grand prize, can you guess why localhost makes it hang when 127.0.0.1 does not?

I checked it out. The file is 'hosts'. I made the change, and it works.

 

Strange. For WinXP  they said not to put localhost in hosts, or at least went out of their way to say it didn't matter. Now it does.

 

Thanks for helping me solve this. The connection between symptom and problem was so tenuous that I might never have found it on my own.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.