• 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
  • Inviting everyone to the UX test of a new security feature in the WP Toolkit
    For WordPress site owners, threats posed by hackers are ever-present. Because of this, we are developing a new security feature for the WP Toolkit. If the topic of WordPress website security is relevant to you, we would be grateful if you could share your experience and help us test the usability of this feature. We invite you to join us for a 1-hour online session via Google Meet. Select a convenient meeting time with our friendly UX staff here.

Issue CurlInitialize for PHP XML API

cipcip

Basic Pleskian
Hi guys,

I did not had any issues with this on my localhost, but apparently as soon as i uploaded to the server, I get errors about the curlinitialize file that i have for API. I can't remember where I took it from now, it was not written by me, but can you help me with this ?

Errors received:

[Sat Jan 26 01:55:12.200814 2019] [proxy_fcgi:error] [pid 9549:tid 140402248107776] [client 188.250.203.236:56547] AH01071: Got error 'PHP message: PHP Warning: curl_setopt(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 22\nPHP message: PHP Warning: curl_exec(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 24\nPHP message: PHP Warning: curl_errno(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 26\nPHP message: PHP Warning: curl_close(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 32\nPHP message: PHP Warning: curl_setopt(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 22\nPHP message: PHP Warning: curl_exec(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 24\nPHP message: PHP Warning: curl_errno(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 26\nPHP message: PHP Warning: curl_close(): supplied resource is not a valid cURL handle resource in /var/www/vhosts/domain/httpdocs/inc/curlInitialize.php on line 32\n', referer: https://domain/signup

The PHP code for the file is:

Code:
<?php
function curlInit($host, $login, $password)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://{$host}:8443/enterprise/control/agent.php");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("HTTP_AUTH_LOGIN: {$login}",
"HTTP_AUTH_PASSWD: {$password}",
"HTTP_PRETTY_PRINT: TRUE",
"Content-Type: text/xml")
);

return $curl;
}

function sendRequest($curl, $packet)
{
curl_setopt($curl, CURLOPT_POSTFIELDS, $packet);

$result = curl_exec($curl);

if (curl_errno($curl)) {
$errmsg = curl_error($curl);
$errcode = curl_errno($curl);
curl_close($curl);
throw new ApiRequestException($errmsg, $errcode);
}
curl_close($curl);
return $result;
}

?>

Thank you
 
I fixed the curl errors, that was a bug from my part.

Now I get:

[Sat Jan 26 10:54:39.742055 2019] [proxy_fcgi:error] [pid 26396:tid 140165766960896] [client 188.250.203.236:52575] AH01067: Failed to read FastCGI header, referer: https://domain/signup
[Sat Jan 26 10:54:39.742098 2019] [proxy_fcgi:error] [pid 26396:tid 140165766960896] (104)Connection reset by peer: [client 188.250.203.236:52575] AH01075: Error dispatching request to : , referer: https://domain/signup

I tried to run a query by itself, to create a subdomain, and it fails, it gives 503 error.
Code used to create a subdomain is:

<?php

include('inc/config.php');
include('inc/curlInitialize.php');

function createSubdomain($nom, $domeniu)
{
$xmldoc = new DomDocument('1.0', 'UTF-8');
$xmldoc->formatOutput = true;
$packet = $xmldoc->createElement('packet');
$packet->setAttribute('version', '1.6.8.0');
$xmldoc->appendChild($packet);
$subdomain = $xmldoc->createElement('subdomain');
$packet->appendChild($subdomain);
$add = $xmldoc->createElement('add');
$subdomain->appendChild($add);
$parent = $xmldoc->createElement('parent', $domeniu);
$add->appendChild($parent);
$name = $xmldoc->createElement('name', $nom);
$add->appendChild($name);
$add->appendChild($xmldoc->createElement('home', $domeniu.'/'.$nom.''));
$property = $xmldoc->createElement('property');
$property->appendChild($xmldoc->createElement('name', 'ssi'));
$property->appendChild($xmldoc->createElement('value', 'true'));
$add->appendChild($property);
return $xmldoc;
}

$subdomeniu = 'test';

$curl = curlInit($host, $login, $pass);
$cerere = createSubDomain($subdomeniu, $domeniu)->saveXML();
printf(htmlspecialchars($cerere));
echo '<br /><br /><br />';
$raspuns = sendRequest($curl, $cerere);
$extractid = array($raspuns);
print_r($extractid);

?>

Same errors in log file as above.
Can this happen because of server resources?

I have a VPS with the following:

Web Space 100 GB SSD
CPU Power 2 vCores
Guaranteed RAM 4 GB
Burst RAM 8 GB
Traffic 100-Mbit/s-Flatrate

Thank you
 
Last edited:
Back
Top