PHP SDK times out with no errors reported

I have a simple payment form and card processing app that has benn working well for the last nine months. Suddenly on 8/13/21 the card processing script started to fail.

catch (ApiException $e) {
  echo 'Caught exception!<br/>';
  print_r("Recieved error while calling Square: " . $e->getMessage());
}

and the returned error is
Operation timed out after 0 milliseconds with 0 out of 0 bytes received

my SDK is “version”: “6.0.0.20200625”
please let me know if there is any other information that might be helpful. Thanks!

i don’t remember where that catch block code came from! so i changed the catch block to something simpler

catch (ApiException $e) {
  echo 'Caught exception!<br/>';
  print_r("Recieved error while calling Square: " . $e->getMessage());
}

and the returned error is
Operation timed out after 0 milliseconds with 0 out of 0 bytes received

i’m bumping this again because i have no idea how to debug it. my sandbox application ID is sandbox-sq0idb-HVgYltGd6znV_k9X2SGIkQ
and production is
sq0idp-ckhLFgBGyO0jsNpIQqFDrw

thanks!
bill

Hi @bsack, I took a look at the logs and see that you successfully created a source_id recently however there are no calls to CreatePayment can you confirm that you are getting the source_id? Also is there any more detail in the error message?

there are no details in the error message that i have been able to discern. i’m not sure what you mean by ‘getting the source_id’ …

Okay, would you mind providing what you are using for the payment request? Also the source_id is the token that our client side form generates to pass to the payment request. I see in the logs that it is being generated however not used to process the payment.

our last sucessful transaction was 08/10/21.

ok, if you want to see the card processing code here it is. pretty standard, i think:

$payments_api = $client->getPaymentsApi();
$money = new Money();
$totalAmount = $_SESSION["TOTAL"];
$money->setAmount($totalAmount);
$money->setCurrency('USD');

$create_payment_request = new CreatePaymentRequest($nonce, uniqid(), $money);

$create_payment_request->setReferenceId('123456');
$note = "Ticket Order: ".$_SESSION['FULL_NAME']." ".session_id();
$create_payment_request->setNote($note);
try {
  $response = $payments_api->createPayment($create_payment_request);
  if ($response->isError()) {
    echo 'Api response has Errors';
    $errors = $response->getErrors();
    
    echo '<pre>';
  print_r($response);
  echo '</pre>';
  
    echo '<ul>';
    foreach ($errors as $error) {
        echo '<li>❌ ' . $error->getDetail() . '</li>';
    }
    echo '</ul>';
    exit();
  }

  //echo '<pre>';
  //print_r($response);
  //echo '</pre>';

} catch (ApiException $e) {
  echo 'Caught exception!<br/>';
  print_r("Recieved error while calling Square: " . $e->getMessage());
}

for whatever it’s worth, i checked with our webhosting service (ASO) and there have been no chaanges to firewalls or anything that would block a request or response.

this is the output of a traceroute to connect.squareup.com from my ASO server:

[email protected] [~]# traceroute 74.122.189.132    
traceroute to 74.122.189.132 (74.122.189.132), 30 hops max, 60 byte packets
 1  xxxx  0.123 ms  0.142 ms  0.131 ms
 2  xxxx 0.075 ms  0.123 ms  0.114 ms
 3  te0-6-0-26.rcr21.b010621-0.dfw01.atlas.cogentco.com (38.32.13.209)  0.583 ms  0.593 ms  0.627 ms
 4  be2560.ccr31.dfw01.atlas.cogentco.com (154.54.5.237)  0.867 ms  1.048 ms be2561.ccr32.dfw01.atlas.cogentco.com (154.54.6.73)  1.194 ms
 5  be2764.ccr41.dfw03.atlas.cogentco.com (154.54.47.214)  1.128 ms be2763.ccr41.dfw03.atlas.cogentco.com (154.54.28.74)  1.057 ms  57.119 ms
 6  telia.dfw03.atlas.cogentco.com (154.54.10.154)  0.919 ms  0.781 ms  0.796 ms
 7  atl-b24-link.ip.twelve99.net (80.91.246.74)  18.961 ms  18.978 ms atl-b24-link.ip.twelve99.net (62.115.123.201)  19.059 ms
 8  ash-bb2-link.ip.twelve99.net (62.115.125.129)  30.534 ms  30.456 ms rest-bb1-link.ip.twelve99.net (62.115.125.190)  32.914 ms
 9  ash-b1-link.ip.twelve99.net (80.91.248.157)  33.217 ms  33.656 ms ash-b1-link.ip.twelve99.net (62.115.143.121)  31.154 ms
10  akamai-ic317112-ash-b1.ip.twelve99-cust.net (62.115.146.129)  30.851 ms akamai-ic317122-ash-b1.ip.twelve99-cust.net (62.115.146.139)  33.221 ms akamai-ic317112-ash-b1.ip.twelve99-cust.net (62.115.146.129)  31.059 ms
11  * po110.bs-a.sech-iad.netarch.akamai.com (209.200.144.192)  33.276 ms  30.771 ms
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

i hope this is helpful? i really need to get my app online again!
Thanks!
bill

The payment request looks good however I’m not seeing any requests to Square to either get the nonce or CreatePayment. It looks like all the request are failing to reach Square. Is your application able to call any other of our APIs?

the same result is returned if i run the simple call to ‘getLocationsApi’ - this is the try and catch portion of that:

try {
    $locationsApi = $client->getLocationsApi();
    $apiResponse = $locationsApi->listLocations();

    if ($apiResponse->isSuccess()) {
        $listLocationsResponse = $apiResponse->getResult();
        $locationsList = $listLocationsResponse->getLocations();
        foreach ($locationsList as $location) {
        print_r($location);
        }
    } else {
        print_r($apiResponse->getErrors());
    }
} catch (ApiException $e) {
    print_r("Recieved error while calling Square: " . $e->getMessage());
} 

doesn’t it seem like the requests are getting blocked somehow?

Yes, that’s what it seems like. They aren’t even making it to Square. All your requests look good. If you try to run this using localhost are you able to get a successful response? If so this would mean that your hosting server calls aren’t making it to Square.

when i try to run that locations.php from a local server i fail on this error:

127.0.0.1:46642 [200]: /location.php - Uncaught InvalidArgumentException: JsonMapper::mapClass() requires first argument to be an object, string given. in /home/bsack/hw_web/square-php-sdk/apimatic/jsonmapper/src/JsonMapper.php:312
Stack trace:
#0 /home/bsack/hw_web/square-php-sdk/src/Apis/LocationsApi.php(84): apimatic\jsonmapper\JsonMapper->mapClass('{"locations":[{...', 'Square\\Models\\L...')
#1 /home/bsack/hw_web/square/location.php(28): Square\Apis\LocationsApi->listLocations()
#2 {main}
  thrown in /home/bsack/hw_web/square-php-sdk/apimatic/jsonmapper/src/JsonMapper.php on line 312

That’s an argument error. Are you using the above locations example? I just tested it’s working as expected.

today i was able to run the locations script from localhost, so that seems to point to a problem with the webserver. my webhosting company, A Small Orange, are not being helpful. they’ve suggested that it has something to do with their mod_security rules, but they only provided me with some logs showing blocked incoming requests from crawlerbots and brute force wordpress login attempts.

so i guess we have to find an alternative method of processing credit card payments or get a new hosting service. do you think the Web Payments SDK would have the same problem? i tried the example application on localhost and it successfully sent a payment to the sandbox …

Do you know what TLS you provider is using? The Web Payments SDK is the client side js that is used your server logic and the PHP SDK.

the provider is using TLS 1.2
they’re saying the squareup ip address is not blocked.
also that the secure cURL connection is also working
this is the quote from the support ticket:

This means that the communication from the server to the API might be blocked may be from the internal firewalls. These API connection issues purely depend on how and what is the impact of these connections from single or multiple IPs at the same instance of time. These are the temporary blocks related to many API connections from the server level.

II. Few other reasons:
-Firewall or security modules (example: mod_security ) that could block the outgoing cURL requests.
-It could sometimes be a conflict of plugins and themes or modules on the site.

after having said that there are no firewalls blocking cURL requests? i don’t understand …

off-topic - is there a place in the documentation anywhere that explicity explains how to use the Web Payments SDK on a server as opposed to running the example on a local computer? Are we supposed to upload the entire node.js server and run that on our servers? It’s not clear …

thank you.

Request that are using TLS 1.2 are valid requests that we accept. I sounds like they were describing rate limiting in their message. If this was rate limiting from too many requests from your server you would have gotten a 429 RATE_LIMIT error. In all honesty I’m not sure what could be blocking the requests.

When you are done testing locally you can follow our guide on deploying the application. You will need to deploy the entire application to your server. :slightly_smiling_face:

still banging my head against the wall here. One strange thing i just noticed is that if i try to call the location.php script on a different network (my neighbor’s wifi, cellular data, etc), or even with a different browser on the same network, that the request and response will work ONCE, with subsequent requests going back to the familiar timeout behavior.

I will have to wait until i get a new hosting service to try the Web Payments SDK, since i can’t run node.js on my current shared hosting. soon …

:wave: That is so frustrating that you aren’t able to make calls with your existing provider. We do have Web Payments SDK examples in other languages available on our connect-api-examples in Git Hub. :slightly_smiling_face: