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”: “”
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


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"];

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

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

  //echo '<pre>';
  //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 from my ASO server:

[email protected] [~]# traceroute    
traceroute to (, 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 (  0.583 ms  0.593 ms  0.627 ms
 4 (  0.867 ms  1.048 ms (  1.194 ms
 5 (  1.128 ms (  1.057 ms  57.119 ms
 6 (  0.919 ms  0.781 ms  0.796 ms
 7 (  18.961 ms  18.978 ms (  19.059 ms
 8 (  30.534 ms  30.456 ms (  32.914 ms
 9 (  33.217 ms  33.656 ms (  31.154 ms
10 (  30.851 ms (  33.221 ms (  31.059 ms
11  * (  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!

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) {
    } else {
} 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: [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: