• Resolved benbakelaar

    (@benbakelaar)


    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 – https://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(“https://www.google.com&#8221;); ?> 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!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter benbakelaar

    (@benbakelaar)

    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]
    Thread Starter benbakelaar

    (@benbakelaar)

    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(https://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 https://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(https://www.mydomain.org/blog/rss.xml): failed to open stream: Connection timed out in /var/www/community/testrss.php on line 3

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    There’s no ‘paid’ version of WP for your iPad. What on earth are you talking about?

    Thread Starter benbakelaar

    (@benbakelaar)

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

    https://www.ads-software.com/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.

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

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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.

    Thread Starter benbakelaar

    (@benbakelaar)

    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.

    Thread Starter benbakelaar

    (@benbakelaar)

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

    Thread Starter benbakelaar

    (@benbakelaar)

    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>
    Thread Starter benbakelaar

    (@benbakelaar)

    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
    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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.

    Thread Starter benbakelaar

    (@benbakelaar)

    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 https://127.0.0.1/blog/rss.xml as the feed address, rather than https://www.princetonlibrary.org/blog/rss.xml.

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

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

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

    Thread Starter benbakelaar

    (@benbakelaar)

    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:

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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘CURL and similar functions failing on local server names’ is closed to new replies.