• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx

  • We are developing a new feature in Plesk that will help you promote your websites or business on social media. We want to conduct a one-hour online UX test to present the prototype and collect feedback. If you are interested in the feature, please book a meeting via this link.
    Thank you in advance!
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question [REST API] Getting ERR::Connection Refused PHP

safemoon

Basic Pleskian
Hello,

I am trying to create a new domain through the REST API in PHP but although the call successfully creates the domain, I get ERR::Connection refused after 2-3 seconds when sending the POST Request. Since the domain gets successfully created I assume that all the parameters and json format is correct. Is there any firewall or specific configuration i need to do, or is it pure php error? The website which is hosted on the same server just goes blank after few seconds

Code below:
Code:
                $url = "https://www.mydomain.com:8443/api/v2/domains/";

                //set the url, number of POST vars, POST data
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
                curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json","cache-control: no-cache","Accept: application/json"));
                curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                curl_setopt($ch, CURLOPT_USERPWD, "admin:password");
                curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

                //execute post
                $result     = curl_exec ($ch);
                $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                
                curl_close ($ch);
 
How did you run this code? Trough command line? Or on a page accessed trough your browser? If so, is it hosted on the same server or locally?
 
It is run with PHP in a website that is hosted on the same server
How did you run this code? Trough command line? Or on a page accessed trough your browser? If so, is it hosted on the same server or locally?

It seems like the request succeeds but it does not get any response back and i get an bet::ERR_EMPTY_RESPONSE error
 
NOTE: When clicking the submit button an HTML form with POST gets submitted and at the same time a PHP CURL POST request is executed.
 
UPDATE: The above note does not change anything... I run the same code in a separate PHP file with no other interactions and it produces the same error.
 
I can actually replicate this issue. If I run this code from the same server I get this 503 error too. If run the code from a remote server/local environment it works without any issues.

What Plesk version and OS are you using?
 
Last edited:
I can actually replicate this issue. If I run this code from the same server I get this 503 error too. If run the code from a remote server/local environment it works without any issues.

What Plesk version and OS are you using?
OS ‪Ubuntu 14.04.6 LTS‬
Product Plesk Onyx Version 17.8.11 Update #53, last updated on Feb 14, 2020 06:29 AM
 
Update: According to a stackoverflow answer adding session_write_close before curl request executes and session_start after the curl request closes did not help at all.

Still stuck...
 
Update 2: I tried the shell_exec() PHP function and it still does not work. Seems like the issue is on the network. Not sure how this can be fixed...
 
To be honest, I think this might be an issue related to Plesk itself. Because, as far as I can see, this issue only happens when you execute the code from the same server you're running Plesk on. I suspect I has something to do with the fact that php-fpm restarts when you add a new domain. Hence the 503 error, and thats also why this issue doesn't happen when you run the code from a remote/local machine.

Not necessarily a bug, but I would say it is certainly undesirable behaviour. I am also not sure if there is a solution to this issue.

@IgorG, do you maybe have any suggestions?
 
Last edited:
I can only say that this is a very specific usage scenario and such things need to be investigated directly on the affected server.
Therefore, I would advise you to contact Plesk support.
 
I've ran some more tests. It definitely seems to be related to FPM. From the PHP-FPM log:
[18-Mar-2021 10:47:32] NOTICE: ready to handle connections [18-Mar-2021 10:47:32] NOTICE: systemd monitor interval set to 10000ms [18-Mar-2021 10:47:33] NOTICE: [pool plesk-php73-fpm.plesk-service.localdomain] child 28449 exited with code 0 after 0.031291 seconds from start [18-Mar-2021 10:47:33] NOTICE: [pool plesk-php73-fpm.plesk-service.localdomain] child 28463 started

@safemoon When you switch your PHP to FastCGI you won't encounter this issue. Which might not be desirable, in that case contact Plesk support (and let us know their solution).
 
Back
Top