• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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