?
SolvedPrivate

How to fix failed communications with Payment Gateways in PHP using Curl/SOAP

Posted on 2014-02-18
6
Medium Priority
?
54 Views
Last Modified: 2016-03-24
My server is showing communication errors with the PayPal SDK, Google API, and other remote servers in the php error log.

Is a 1-2% failure rate for communicating with other servers acceptable?

Where do I start looking to optimize?  I am running a LAMP system.

Do I optimize something in php.ini for CURL and SOAP?
0
Comment
Question by:phpzilla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 39869221
What is the timeout setting you have set?  You might want to try adding a little more time on that and see if that helps.
0
 

Author Comment

by:phpzilla
ID: 39869236
Timeout settings where?  php.ini, the gateway api, ...

How do I diagnose failed communications on linux, is there a log file?
0
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 39869251
Look into this:  http://www.php.net/manual/en/function.set-time-limit.php

And check this out:  http://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php

The first one is about setting it up in php.ini or setting it in code.  The second one is regarding the CURL timeout specifically.
0
Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39870242
Is a 1-2% failure rate for communicating with other servers acceptable?
"Acceptable" is a pretty broad term.  Some questions to help run this to ground...

Are you on a shared server?

What PHP functions are causing the "communications errors?"

Are you using cURL error reporting?

Have you tried fsockopen() to speak with the APIs?
0
 

Author Comment

by:phpzilla
ID: 39870710
using curl

Should I always set CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT?

Are system defaults set somewhere for CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT?

Does /etc/php5/apache2/phi.ini->max_execution_time affect CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT or does max_execution_time get suspeneded with a call is made to an external system via curl?

is there a difference with curl in apache (browser) vs cli (command line cron jobs?)
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39871107
That seems like several questions.  I'll try to help with the cURL part.  Here is my teaching example showing how to make a cURL POST-method request.  I do not know about CURLOPT_CONNECTTIMEOUT.  I use CURLOPT_TIMEOUT to prevent a "hang" condition.  If you don't do that your cURL connection time is added to your script execution time for as long as it takes the remote service to respond.  I don't know what the system default might be; I always set the value I want explicitly.

<?php // RAY_curl_post_example.php
error_reporting(E_ALL);


// DEMONSTRATE HOW TO USE CURL POST TO START AN ASYNCHRONOUS PROCESS


function curl_post($url, $post_array=array(), $timeout=2, $error_report=TRUE)
{
    // PREPARE THE POST STRING
    $post_string = NULL;
    foreach ($post_array as $key => $val)
    {
        $post_string .= $key . '=' . urlencode($val) . '&';
    }
    $post_string = rtrim($post_string, '&');

    // PREPARE THE CURL CALL
    $curl = curl_init();
    curl_setopt( $curl, CURLOPT_URL,            $url         );
    curl_setopt( $curl, CURLOPT_HEADER,         FALSE        );
    curl_setopt( $curl, CURLOPT_POST,           TRUE         );
    curl_setopt( $curl, CURLOPT_POSTFIELDS,     $post_string );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout     );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE         );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );

    // EXECUTE THE CURL CALL
    $htm = curl_exec($curl);
    $err = curl_errno($curl);
    $inf = curl_getinfo($curl);

    // ON FAILURE
    if (!$htm)
    {
        // PROCESS ERRORS HERE
        if ($error_report)
        {
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            echo "<pre>\n";
            var_dump($inf);
            echo "</pre>\n";
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS
    curl_close($curl);
    return $htm;
}


// USAGE EXAMPLE CREATES ASSOCIATIVE ARRAY OF KEY=>VALUE PAIRS
$args["name"]  = 'Ray';
$args["email"] = 'Ray.Paseur@Gmail.com';

// ACTIVATE THIS TO SEE THE ARRAY OF ARGS
// var_dump($args);

// SET THE URL
$url = "http://LAPRBass.com/RAY_bounce_post.php";

// CALL CURL TO POST THE DATA
$htm = curl_post($url, $args, 3, TRUE);

// SHOW WHAT CAME BACK, IF ANYTHING
if ($htm)
{
    echo "<pre>";
    echo htmlentities($htm);
}
else
{
    echo "NO RESPONSE YET FROM $url -- MAYBE BECAUSE IT IS RUNNING ASYNCHRONOUSLY";
}

Open in new window

0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question