WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] CURL and similar functions failing on local server names (14 posts)

  1. benbakelaar
    Member
    Posted 2 years ago #

    Whenever a local server file is referenced via URL, the load function times out. Examples of functions: file_get_contents(), any of the CURL stuff, getimageresize().

    I've checked and allow_url_fopen is enabled. Also CURL is installed.

    The problem surfaced in two scenarios:

    1. I installed the paid version of WP to iPad. It attempts to load a file via URL when using the getimageresize() function, and times out. The timeout is what shows up in the php_errors.log.

    2. I installed the FeedWordPress plugin, and when attempting to load an RSS feed from a Drupal site on a different sub-domain server, it fails.

    TESTING AND DETAILS

    A. 1 web server - mydomain.org
    B. 1 Drupal site - http://www.mydomain.org
    C. 1 WP multi-site install - community.mydomain.org/<instance>

    Both of the problems are surfacing in C. The WP to iPad plugin cannot load an image via URL/HTTP request that is on the same server C. The FeedWordPress plugin cannot load an RSS feed via URL/HTTP request that is on B.

    I am positive this is due to the .htaccess rewrite rules. I need to figure out how to write some exception rules so that when a WP instance on C requests a URL, it resolves correctly. FYI I even tried via IP address, that didn't work.

    BUT, I can write a simple <?php echo file_get_contents("http://www.google.com"); ?> script and this works fine on B and C. So again the only issue is a URL/HTTP request from B or C that attempts to load a resource on B or C.

    Any help appreciated!

  2. benbakelaar
    Member
    Posted 2 years ago #

    I don't know how to interpret this section of the .htaccess file but I think this is what is interfering.

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
  3. benbakelaar
    Member
    Posted 2 years ago #

    Here are the two errors:

    This is the failure of the WP to iPad plugin (on c.mydomain.org/bookfestival) to load an image resource on the same domain (c.mydomain.org/bookfestival).

    [23-Jul-2012 17:05:35] PHP Warning:  getimagesize(http://c.mydomain.org/bookfestival/wp-content/plugins/wp-to-ipad/images/wpti-logo.png): failed to open stream: Connection timed out in /var/www/community/wp-content/plugins/wp-to-ipad/themes/appzine/header.php on line 71

    This is the failure of the FeedWordPress plugin installed on c.mydomain.org/m to import an RSS feed from http://www.mydomain.org. Note it is the same server, just a different sub-domain.

    [23-Jul-2012 15:02:33] PHP Warning:  file_get_contents(http://www.mydomain.org/blog/rss.xml): failed to open stream: Connection timed out in /var/www/community/testrss.php on line 3
  4. There's no 'paid' version of WP for your iPad. What on earth are you talking about?

  5. benbakelaar
    Member
    Posted 2 years ago #

    That really has little to do with my question, but this is it.

    http://wordpress.org/extend/plugins/wp-to-ipad/

    With WP-to-iPad you can easily create and publish an iPad magazine with WordPress. Offer your WordPress blog readers an optimized version for iPad with just a few clicks! Opt for the paid version to take advantage of various options to customize your iPad magazine.

    http://wp-to-ipad.kinoa.com/

  6. Both of those actually imply the same thing: You have a server configuration problem.

    I ran the same test with pulling in a feed via CURL on my local server (from another install of a separate app on the same server within the same account), and had no issues. So something on the server's got to be wrong, as WP doesn't actually do much with CURL except call it from your server.

  7. benbakelaar
    Member
    Posted 2 years ago #

    Hmm so you don't think it is related to the .htaccess file? You tested on a multi-site install with sub-directories? I don't think it's the same environment if it's two separate installed instances of WP regular. I've never had issues like this with WP regular, just multisite, which I know is a tricky beast.

  8. benbakelaar
    Member
    Posted 2 years ago #

    Here are some details on the server from phpinfo:

    Apache Version 	Apache/2.2.17 (Ubuntu)
    Hostname:Port 	community.princetonlibrary.org:0
    User/Group 	www-data(33)/33
    Server Root 	/etc/apache2
    HTTP_HOST 	community.princetonlibrary.org
    SERVER_NAME 	community.princetonlibrary.org
    DOCUMENT_ROOT 	/var/www/community/
    allow_url_fopen	On	On
    allow_url_include	Off	Off
    cURL support 	enabled
    cURL Information 	7.21.3

    In tests using file_get_contents() and a curl() function, I can load http://www.google.com without issue. I assume this means I can load any other domain as well. But if I try to load a URL on the server itself, e.g. community.princetonlibrary.org/bookfestival/wp-content/plugins/wp-to-ipad/images/wpti-logo.png, or a URL on a different sub-domain on the same server, e.g. http://www.princetonlibrary.org/blog/rss.xml, the request times out with the "failed to open stream" error. Both of these URLs exist and can be loaded in a browser.

    Obviously the server is having trouble referring to itself. Looking for ideas about why this might be. I think it is related to the htaccess rewrite code. I've been working with Apache/PHP/MySQL and WordPress for many years now, but only recently with multi-site. Everything functions normally, just this issue.

    The plugins that are actually "causing" this issue are:
    - WP-to-iPad (renders an iPad version of site)
    - FeedWordPress (allows you to import RSS feeds)

    But the problem has nothing to do with the plugins themselves, just the functions they are using to retrieve resources on the server.

  9. benbakelaar
    Member
    Posted 2 years ago #

    Also here is the Apache virtualhost configuration:

    <VirtualHost *:80>
        ServerAdmin me@myserver
        DocumentRoot /var/www/community/
        ServerName community.princetonlibrary.org
        ServerAlias community
        RewriteEngine On
        RewriteOptions inherit
        CustomLog /var/log/apache2/community.log combined
        Options -Indexes FollowSymLinks
    </VirtualHost>
  10. benbakelaar
    Member
    Posted 2 years ago #

    And I wonder if it has something to do with this error when I restart Apache?

    root@PPLWebServer:/var/www/community# service apache2 restart
     * Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
     ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
  11. Hmm so you don't think it is related to the .htaccess file? You tested on a multi-site install with sub-directories?

    I have a subdirectory install, a subdomain, and a mapped domain :) I get around ;)

    I acutally pull in RSS like that from a wiki and a gallery all the time, never had an issue.

    But ... The FQDN error certainly is suspect.

  12. benbakelaar
    Member
    Posted 2 years ago #

    Yea I'm poking around for support for the FQDN/configuration error. I suppose I might eventually be able to figure it out but I just don't understand every layer in enough detail to know how to fix or isolate the issue.

    Re: my actual issues, I did manage to solve one of them. I tricked the FeedWordPress plugin by using http://127.0.0.1/blog/rss.xml as the feed address, rather than http://www.princetonlibrary.org/blog/rss.xml.

    That won't fix my problem with resource loading on the WP-to-iPad plugin though.

  13. No, but it does somewhat confirm that the FQDN is the cause here.

  14. benbakelaar
    Member
    Posted 2 years ago #

    FINALLY fixed!

    I started to narrow down on DNS issues as the cause. (duh)

    I checked out /etc/resolv.conf, and was reading articles about editing it. But then I tried some "ping" commands to the sub-domains in question, and the pings worked. So it didn't appear to be DNS issue.

    Then I found this question, which pretty much exactly described the same problem I was having:

    http://serverfault.com/questions/380288/curl-request-wont-resolve-to-localhost

    No resolution there, but I took another look at the /etc/hosts file. Because I was able to "trick" FeedWordPress into importing my main website's RSS feed via 127.0.0.1, I decided to add entries for the sub-domains in /etc/hosts under 127.0.0.1 (they were already entered as the external IP).

    THIS SOLVED THE PROBLEM!

    I did have to restart networking - on Ubuntu Linux, it is /etc/init.d/networking restart.

    I hope this info ends up helping someone else some day. Really frustrating. I guess the answer is:

    If you are running multiple virtual hosts on an Apache server, and want CURL/file_get_contents and similar functions to be able to access resources via FQDN, you need to associate the sub-domains with the localhost address (127.0.0.1) in your /etc/hosts file.

Topic Closed

This topic has been closed to new replies.

About this Topic