Re: curl_exec hangs/freezes on shared hosting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
* @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;

?>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux