[GH-ISSUE #245] cURL transport error: 7 Failed to connect to api.spotify.com port 443: Timed out in #176

Closed
opened 2026-02-27 19:26:27 +03:00 by kerem · 12 comments
Owner

Originally created by @omadepod on GitHub (Jan 12, 2022).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/245

Since about a year my scripts stop in the middle of my page with the curl transport error (see subject). I tried adding a sleep(1) command but it doesn't help much.

Many thanks

Originally created by @omadepod on GitHub (Jan 12, 2022). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/245 Since about a year my scripts stop in the middle of my page with the curl transport error (see subject). I tried adding a sleep(1) command but it doesn't help much. Many thanks
kerem 2026-02-27 19:26:27 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Jan 12, 2022):

Hi!
Are you behind a firewall, proxy, or similar? That's usually the issue with these kind of errors.

<!-- gh-comment-id:1011369362 --> @jwilsson commented on GitHub (Jan 12, 2022): Hi! Are you behind a firewall, proxy, or similar? That's usually the issue with these kind of errors.
Author
Owner

@omadepod commented on GitHub (Jan 12, 2022):

Hi!

I have windows firewall running but firefox is allowed there and i have orange internet for which i never need to use a proxy.

<!-- gh-comment-id:1011430842 --> @omadepod commented on GitHub (Jan 12, 2022): Hi! I have windows firewall running but firefox is allowed there and i have orange internet for which i never need to use a proxy.
Author
Owner

@jwilsson commented on GitHub (Jan 13, 2022):

Hmm, does it work connecting to any other URL. For example:

<?php
require 'vendor/autoload.php';

$request = new SpotifyWebAPI\Request();

var_dump($request->send('GET', 'https://example.com'));
<!-- gh-comment-id:1012325728 --> @jwilsson commented on GitHub (Jan 13, 2022): Hmm, does it work connecting to any other URL. For example: ```php <?php require 'vendor/autoload.php'; $request = new SpotifyWebAPI\Request(); var_dump($request->send('GET', 'https://example.com')); ```
Author
Owner

@omadepod commented on GitHub (Jan 14, 2022):

yes this works perfectly :

array(4) { ["body"]=> NULL ["headers"]=> array(13) { ["content-encoding"]=> string(4) "gzip" ["accept-ranges"]=> string(5) "bytes" ["age"]=> string(6) "465613" ["cache-control"]=> string(14) "max-age=604800" ["content-type"]=> string(24) "text/html; charset=UTF-8" ["date"]=> string(29) "Fri, 14 Jan 2022 12:12:20 GMT" ["etag"]=> string(17) ""3147526947+gzip"" ["expires"]=> string(29) "Fri, 21 Jan 2022 12:12:20 GMT" ["last-modified"]=> string(29) "Thu, 17 Oct 2019 07:18:26 GMT" ["server"]=> string(14) "ECS (dcb/7F15)" ["vary"]=> string(15) "Accept-Encoding" ["x-cache"]=> string(3) "HIT" ["content-length"]=> string(3) "648" } ["status"]=> int(200) ["url"]=> string(19) "https://example.com" }

my fatal error in my test script:

Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: cURL transport error: 28 Failed to connect to api.spotify.com port 443: Timed out in C:_xampp\htdocs\system\spotify\src\Request.php:225 Stack trace: #0 C:_xampp\htdocs\system\spotify\src\Request.php(132): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', 'limit=20&time_r...', Array) #1 C:_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(124): SpotifyWebAPI\Request->api('GET', '/v1/me/top/trac...', Array, Array) #2 C:_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(1227): SpotifyWebAPI\SpotifyWebAPI->sendRequest('GET', '/v1/me/top/trac...', Array) #3 C:_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(2105): SpotifyWebAPI\SpotifyWebAPI->getMyTop('tracks', Array) #4 C:_xampp\htdocs\includes\ajax_spotify.php(283): SpotifyWebAPI\SpotifyWebAPI->mycms_get_spotify_my_top('tracks', 'short_term') #5 {main} thrown in C:_xampp\htdocs\system\spotify\src\Request.php on line 225

<!-- gh-comment-id:1013069904 --> @omadepod commented on GitHub (Jan 14, 2022): yes this works perfectly : array(4) { ["body"]=> NULL ["headers"]=> array(13) { ["content-encoding"]=> string(4) "gzip" ["accept-ranges"]=> string(5) "bytes" ["age"]=> string(6) "465613" ["cache-control"]=> string(14) "max-age=604800" ["content-type"]=> string(24) "text/html; charset=UTF-8" ["date"]=> string(29) "Fri, 14 Jan 2022 12:12:20 GMT" ["etag"]=> string(17) ""3147526947+gzip"" ["expires"]=> string(29) "Fri, 21 Jan 2022 12:12:20 GMT" ["last-modified"]=> string(29) "Thu, 17 Oct 2019 07:18:26 GMT" ["server"]=> string(14) "ECS (dcb/7F15)" ["vary"]=> string(15) "Accept-Encoding" ["x-cache"]=> string(3) "HIT" ["content-length"]=> string(3) "648" } ["status"]=> int(200) ["url"]=> string(19) "https://example.com" } my fatal error in my test script: Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: cURL transport error: 28 Failed to connect to api.spotify.com port 443: Timed out in C:\_xampp\htdocs\system\spotify\src\Request.php:225 Stack trace: #0 C:\_xampp\htdocs\system\spotify\src\Request.php(132): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', 'limit=20&time_r...', Array) #1 C:\_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(124): SpotifyWebAPI\Request->api('GET', '/v1/me/top/trac...', Array, Array) #2 C:\_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(1227): SpotifyWebAPI\SpotifyWebAPI->sendRequest('GET', '/v1/me/top/trac...', Array) #3 C:\_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(2105): SpotifyWebAPI\SpotifyWebAPI->getMyTop('tracks', Array) #4 C:\_xampp\htdocs\includes\ajax_spotify.php(283): SpotifyWebAPI\SpotifyWebAPI->mycms_get_spotify_my_top('tracks', 'short_term') #5 {main} thrown in C:\_xampp\htdocs\system\spotify\src\Request.php on line 225
Author
Owner

@jwilsson commented on GitHub (Jan 15, 2022):

Have you tried increasing the timeout for cURL using the CURLOPT_CONNECTTIMEOUT, CURLOPT_TIMEOUT, or both of those options? if not, docs around that is available here. You also try setting the CURLOPT_CAINFO option to null and see if that makes any difference.

<!-- gh-comment-id:1013678793 --> @jwilsson commented on GitHub (Jan 15, 2022): Have you tried increasing the timeout for cURL using the `CURLOPT_CONNECTTIMEOUT`, `CURLOPT_TIMEOUT`, or both of those options? if not, docs around that is [available here](https://github.com/jwilsson/spotify-web-api-php/blob/4ec7242fbaaf2df382d1545f169e8ef8ad7b2006/docs/examples/setting-custom-curl-options.md). You also try setting the `CURLOPT_CAINFO` option to `null` and see if that makes any difference.
Author
Owner

@omadepod commented on GitHub (Jan 15, 2022):

with

protected $options = [
'curl_options' => [CURLOPT_CONNECTTIMEOUT => 0, CURLOPT_TIMEOUT => 0],
'return_assoc' => false,
];

there's no difference

with

protected $options = [
'curl_options' => [CURLOPT_CAINFO => null],
'return_assoc' => false,
];

i get this new error :

Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: cURL transport error: 77 error setting certificate verify locations: CAfile: CApath: none in C:_xampp\htdocs\system\spotify\src\Request.php:225 Stack trace: #0 C:_xampp\htdocs\system\spotify\src\Request.php(110): SpotifyWebAPI\Request->send('POST', 'https://account...', 'grant_type=refr...', Array) #1 C:_xampp\htdocs\system\spotify\src\Session.php(204): SpotifyWebAPI\Request->account('POST', '/api/token', Array, Array) #2 C:_xampp\htdocs\system\spotify\src\class.omdp.spotify.php(55): SpotifyWebAPI\Session->refreshAccessToken('AQB4tGsSLV7mg8l...') #3 C:_xampp\htdocs\system\spotify\index.php(151): Spotify_api_access->mycms_get_spotify_connection() #4 {main} thrown in C:_xampp\htdocs\system\spotify\src\Request.php on line 225

<!-- gh-comment-id:1013687955 --> @omadepod commented on GitHub (Jan 15, 2022): with protected $options = [ 'curl_options' => [CURLOPT_CONNECTTIMEOUT => 0, CURLOPT_TIMEOUT => 0], 'return_assoc' => false, ]; there's no difference with protected $options = [ 'curl_options' => [CURLOPT_CAINFO => null], 'return_assoc' => false, ]; i get this new error : Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: cURL transport error: 77 error setting certificate verify locations: CAfile: CApath: none in C:\_xampp\htdocs\system\spotify\src\Request.php:225 Stack trace: #0 C:\_xampp\htdocs\system\spotify\src\Request.php(110): SpotifyWebAPI\Request->send('POST', 'https://account...', 'grant_type=refr...', Array) #1 C:\_xampp\htdocs\system\spotify\src\Session.php(204): SpotifyWebAPI\Request->account('POST', '/api/token', Array, Array) #2 C:\_xampp\htdocs\system\spotify\src\class.omdp.spotify.php(55): SpotifyWebAPI\Session->refreshAccessToken('AQB4tGsSLV7mg8l...') #3 C:\_xampp\htdocs\system\spotify\index.php(151): Spotify_api_access->mycms_get_spotify_connection() #4 {main} thrown in C:\_xampp\htdocs\system\spotify\src\Request.php on line 225
Author
Owner

@jwilsson commented on GitHub (Jan 16, 2022):

Hmm, which API method are you using when the error occurs? Does it work for other methods or is it always the same error?

I can't reproduce it locally and there's been a number of people with this kind of issue over the years but we've never been able to solve it, hence all the questions. I'm a but curious of what it could be and would like to find at least one solution to it 😄

<!-- gh-comment-id:1013882559 --> @jwilsson commented on GitHub (Jan 16, 2022): Hmm, which API method are you using when the error occurs? Does it work for other methods or is it always the same error? I can't reproduce it locally and there's been a number of people with this kind of issue over the years but we've never been able to solve it, hence all the questions. I'm a but curious of what it could be and would like to find at least one solution to it 😄
Author
Owner

@omadepod commented on GitHub (Jan 18, 2022):

for example on this one :

$arr = $api->getMyTop("tracks", ["limit" => 2, "time_range" => "short_term"]);
echo '

'.print_r( $arr, 1 ).'
';
exit();

<!-- gh-comment-id:1015934429 --> @omadepod commented on GitHub (Jan 18, 2022): for example on this one : $arr = $api->getMyTop("tracks", ["limit" => 2, "time_range" => "short_term"]); echo '<pre>'.print_r( $arr, 1 ).'</pre>'; exit();
Author
Owner

@jwilsson commented on GitHub (Jan 20, 2022):

Can you try with another method? $api->me() for example. But you're able to get the access tokens correctly without any errors?

<!-- gh-comment-id:1017846626 --> @jwilsson commented on GitHub (Jan 20, 2022): Can you try with another method? `$api->me()` for example. But you're able to get the access tokens correctly without any errors?
Author
Owner

@omadepod commented on GitHub (Jan 21, 2022):

$api->me(); gives the same error ... and no i don't get errors with the access tokens. [session:protected] => SpotifyWebAPI\Session Object is filled with information. The other fields in SpotifyWebAPI\SpotifyWebAPI Object
are empty though.

<!-- gh-comment-id:1018725018 --> @omadepod commented on GitHub (Jan 21, 2022): $api->me(); gives the same error ... and no i don't get errors with the access tokens. [session:protected] => SpotifyWebAPI\Session Object is filled with information. The other fields in SpotifyWebAPI\SpotifyWebAPI Object are empty though.
Author
Owner

@jwilsson commented on GitHub (Jan 23, 2022):

This is very strange. But you said you could access api.spotify.com using a browser, right? Could you also try the following:

  • Pinging api.spotify.com and see if that works.
  • Double check your hosts file to see that there's nothing in there pointing api.spotify.com somewhere else.
<!-- gh-comment-id:1019518916 --> @jwilsson commented on GitHub (Jan 23, 2022): This is very strange. But you said you could access `api.spotify.com` using a browser, right? Could you also try the following: * Pinging `api.spotify.com` and see if that works. * Double check your `hosts` file to see that there's nothing in there pointing `api.spotify.com` somewhere else.
Author
Owner

@omadepod commented on GitHub (Mar 13, 2022):

I removed a bad ip i found somewhere on internet from my hosts file and now i have correct results with $api->me();

Seems like i get blocked when trying too much requests in my scripts. After a big script i get errors and can't even connect to my account but when i refresh it works again.

For example i want to find new releases from all my favourite artists so i need to query all my playlists, then albums from the artists and their date of release. Doing this gives the original Failed to connect to api.spotify.com port 443: Timed out error.

<!-- gh-comment-id:1066180250 --> @omadepod commented on GitHub (Mar 13, 2022): I removed a bad ip i found somewhere on internet from my hosts file and now i have correct results with $api->me(); Seems like i get blocked when trying too much requests in my scripts. After a big script i get errors and can't even connect to my account but when i refresh it works again. For example i want to find new releases from all my favourite artists so i need to query all my playlists, then albums from the artists and their date of release. Doing this gives the original Failed to connect to api.spotify.com port 443: Timed out error.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#176
No description provided.