I have a very weird situation on my hands and I cannot understand what is happening. It is a true mystery.

I am using a theme called, IpinPro its basically a Pinterest clone. It all works perfectly fine with the exception for fetching images.

What makes it so mysterious is that fetching the images works perfectly fine when WP_DEBUG is set to true. When WP_DEBUG is false, the timeouts return.

So when:

WP_DEBUG = TRUE , the code below works perfectly fine

WP_DEBUG = FALSE, the code below DOESNT work and will timeout on mod_fcgid

Let me first show the code that is part of this mystery.

Everything is peachy all upto curl_exec. I added logging to a file myself, but nothing is logged.

    if (function_exists('curl_init')) {
        $ch = curl_init();

        $fp = fopen("curl_exec.log", 'a+');

        curl_setopt($ch, CURLOPT_URL, $imgsrc);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

//extra options added by me, to figure out what is going in.
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
        curl_setopt($ch, CURLOPT_STDERR, $fp);

        $image = curl_exec($ch);
        fclose ($fp);

        if($image === false) {
            $curl_error = curl_error($ch);

    } elseif (ini_get('allow_url_fopen')) {
        $image = file_get_contents($imgsrc, false, $context);

The error messages that I see :

[Thu Dec 11 22:17:14 2014] [warn] [client X.X.X.X] mod_fcgid: read data timeout in 31 seconds, referer: http://somesite.nl/itm-settings/
[Thu Dec 11 22:17:14 2014] [warn] [client X.X.X.X] (110)Connection timed out: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function, referer: http://somesite.nl/itm-settings/

[Thu Dec 11 22:42:14 2014] [warn] [client X.X.X.X] mod_fcgid: read data timeout in 31 seconds, referer: http://somesite.nl/itm-settings/
[Thu Dec 11 22:42:14 2014] [error] [client X.X.X.X] Premature end of script headers: index.php, referer: http://somesite.nl/itm-settings/

I have no clue what is going on.

Increasing timeout for MOD_FCGID is no solution. Because the codes works flawlessly when WP_DEBUG = TRUE.


  • What was your reasoning behind using curl directly rather than the WP_HTTP APIs? Have you verified your server can actually reach the remote location on the command line? The mod_fcgid: ap_pass_brigade failed implies this is a mod_fcgid issue, what does your PHP error log say? – Tom J Nowell Dec 12 '14 at 0:15
  • mod_fcgid? How can that be possible when the code works when WP_DEBUG is TRUE? – user1973842 Dec 12 '14 at 0:22
  • I said implies, can you check your PHP error log? It may provide more information. Do the WP HTTP apis work? Is there any reason you didn't use $image = wp_remote_get( $imgsrc );? – Tom J Nowell Dec 12 '14 at 0:24
  • PHP error log is already pasted in the main question. There are no other error messages. I tried wp_remote_get and guess what, with WP_DEBUG = TRUE, it works. when WP_DEBUG = FALSE, it will cause a time out. – user1973842 Dec 12 '14 at 10:43
  • just to be thorough I created a test.php file with the exact same code as above, and exec_curl works flawlessly. This is Wordpress related, somehow. – user1973842 Dec 12 '14 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.