views:

810

answers:

6

Hey everyone,

I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server.

The error is:

PHP Warning:  imagecreatefromjpeg(): php_network_getaddresses: 
  getaddrinfo failed: Name or service not known in /path/to/script.php
  on line 75

The line of code on 75 is:

$this->img = imagecreatefromjpeg(PHPTHUMB."?src=/".$this->image_path);

which creates an image that is loaded from another made by phpThumb, which is used for further manipulation.

Any ideas on how to solve this? Can anyone shed some light on what the error means?

Thank you,

Edit: Just as a further bit of insight, if i visit PHPTHUMB . "?src=/" . $this->image_path in my browser, the image loads fine

User agent in php.ini did not solve the problem as indicated here

EDIT (SOLUTION): I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly. Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly. Thanks for everyone's efforts,

+5  A: 

I'm totally not sure about the cause of that error, but this is my best guess.

There is a particular PHP Setting which enables you to treat URLs as files. Normally imagecreatefromjpeg accepts a filename, I think. Since you are passing a URL, you need to make sure the particular setting is enabled. I believe you can find more info about it here: http://us2.php.net/file

filename

Path to the file.
Tip

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and List of Supported Protocols/Wrappers for a list of supported URL protocols.

Fopen wrappers: http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Your dev environment may not be setup with this, but your production environment could be.

Edit

This page lists your error: http://bugs.php.net/bug.php?id=11058

and mentions that a possible fix is by modifying your hosts file to explicitly include the ip/dns of the server you're accessing.

i tryed to reconfigure my named configuration, without any result, to fix this. the problem was solved by adding the following line to my /etc/hosts:

194.97.55.147 mx.freenet.de

Maybe you can try this?

Jamie
allow-url-fopen is set to 'On' in my php.ini
barfoon
edited my previous comment. Perhaps the page I referenced will resolve things? Try editing the hosts file.
Jamie
Tried adding my external IP to the hosts and it does not work.
barfoon
I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly.Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly.
barfoon
A: 

The error message suggests something is wrong at a networking level. Thus, if possible, bypass that. Try using the path to the thumbnail generator, instead of a network address.

If that's not an option, try something that will give you more granular error messages. I suggest CURL. At the very least, it should yield a more informative error message.

Kalium
I have tried including the full path to the thumbnail generator, and that didnt work. It appears that it cant open the URL in the image function. But besides allow_url_fopen, I don't know what else to try.
barfoon
A: 

Any other ideas? I'd greatly appreciate any more thoughts. Thank you,

barfoon
+1  A: 

Hi,
did you also check that allow_url_fopen is set to On in php.ini?
I saw that they did mention that in the article you referred to in your post.


EDIT: Also, what OS and what PHP version are you running? Just read this on php.net:

"On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the GD Functions extension."


EDIT2:

I just read what was written in the comments, your allow_url_fopen is set to On, sorry about that. But OS, PHP version and phpinfo() would help in finding the problem.

fredrik
A: 

The simple fact that this is failing is because on your webserver, your DNS resolution is broken.

If you have SSH access to your server, try the following command

dig hostname

where hostname is the host name from PHPTHUMB

This will probably fail.

Assuming that you're using Linux, my suggestion would be to edit your /etc/resolv.conf (as root)

and add the following line before any other lines beginning with "nameserver"

nameserver 4.2.2.2

This should hopefully fix things, though you may have to restart apache (or whatever webserver you're using)!

Mez
What is 4.2.2.2, a public DNS service? The url I am working with is http://dev.mysite.com, which resolves to a virtual machine I have running on my host - it is not a publicly viewable site.
barfoon
yeah, it's a public DNS Service.Again, it's still a case that your resolver doesnt go back to the right place.
Mez
A: 

The issue here is that php fails to resolve the url that you provide as PHPTHUMB as stated in this bug report on php.net. This possibly means that it's the fault of the operating system/web server, in which case you can enter the ip address of the server you are connecting to into your hosts file manually.

soulmerge