Re: curl_exec hangs/freezes on shared hosting

From: Date: Thu, 25 Sep 2008 12:15:06 +0000
Subject: Re: curl_exec hangs/freezes on shared hosting
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-280914@lists.php.net to get a copy of this message
It's actually the server i'm calling that's at fault, it didn't serve connections from the outside world.. So not a php thing at all, sry for the wasted time.. Rene Veerman wrote:
I use the following script to make forward an ajax call from the browser to a server other than my main webserver. On my homeserver (debian/apache2/php5 with rootxs) it runs fine, but on my shared hosting (servage.net, phpinfo at http://mediabeez.veerman.ws/mb/sn.php) it freezes / hangs on curl_exec(). I've already asked my hoster's supportstaff about this, but they are a bit clueless and are very slow to respond atm. So i'm wondering if you know anything about curl_exec hanging/freezing because of some server configuration setting. If i'd know what it is that's causing this, maybe i can work around it? I'd also like to know about forward-scripts that can do POST and GET, and use fopen() instead of curl. Maybe that fixes it. The script I currently use: <?php /** * Transport for Cross-domain AJAX calls * * This is an implementation of a transport channel for utilizing cross-domain * AJAX calls. This script is passed the data through AJAX along with two special * hidden field containing the action URL and the http method (GET/POST). It then * sends the form fields to that URL and returns the response. *
* @package        CrossDomainAjax
* @category    CURL
* @author        Md Emran Hasan <phpfour@gmail.com>
* @link        http://www.phpfour.com
*/ require_once ('lib_html.php'); // The actual form action $action = $_REQUEST['url']; // Submission method $method = $_REQUEST['method']; // Query string $fields = ''; // Prepare the fields for query string, don't include the action URL OR method if (count($_REQUEST) > 2) { foreach ($_REQUEST as $key => $value) {
       if ($key != 'url' || $key != 'method')
       {
           $fields .= $key . '=' . rawurlencode($value) . '&';
       }
} } // Strip the last comma $fields = substr($fields, 0, strlen($fields) - 1); // Initiate cURL $ch = curl_init(); // Do we need to POST of GET ? if (strtoupper($method) == 'POST')
{     curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); } else { curl_setopt($ch, CURLOPT_URL, $action . '?' . $fields); } // Follow redirects and return the transfer curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($connection, CURLOPT_TIMEOUT, 45);            // 45 secs. download page
       curl_setopt($connection, CURLOPT_CONNECTTIMEOUT, 30);         // 30 server found
       curl_setopt($connection, CURLOPT_VERBOSE, 1);
// Get result and close cURL //tmlDump ($action); $result = curl_exec($ch); curl_close($ch); // Return the response echo $result; ?>


« previous php.general (#280914) next »