1

I am using a cURL to notify remote site of some updates on my site. I use it with hook_user_update() which is used when user data is saved. Problem is that it takes a lot of time to do that (maybe slow remote server). User saving is slow and it takes sometimes a minute or two.

How could I make this work that cURL doesn't hang user update and they are not dependent in this way?

This is the code I am using now

/**
 * Implemention of hook_user_update(), Notify OS after updating user account
 */
function os_integration_user_update(&$edit, $account, $category) {
  $query = array(
    'source' => 'web',
    'action' => 'nCustomer',
    'customer_id' => $account->uid,
    );

  $url = url('http://admin.com/synch/index.php', array('query' => $query));

$username = 'admin_os';
$password = 'admin_pass';
$basic = base64_encode($username . ':' . $password);

$headerArr = array();
$headerArr[] = 'Authorization: Basic ' . $basic;

$ch = curl_init( $url ) ; 
curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr ); 
curl_setopt( $ch, CURLOPT_HEADER, 1);
// Execute
curl_exec($ch);

// Check if any error occurred
if(!curl_errno($ch))
{
 $info = curl_getinfo($ch);

 echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
 watchdog('lelo_os_integration_os_error', 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']);
 // other info data http://php.net/manual/en/function.curl-getinfo.php
}

// Close handle
curl_close($ch);
}
0

The HTTPRL project provides you with a non-blocking HTTP client.

$url = url('http://admin.com/synch/index.php', array('query' => $query));
$username = 'admin_os';
$password = 'admin_pass';
$basic = base64_encode($username . ':' . $password);

httprl_request($url, array(
  'blocking' => FALSE,
  'headers' => array(
    'Authorization' => 'Basic '.$basic,
    'Host' => $_SERVER['HTTP_HOST']
   ),
));
$request = httprl_send_request();
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.