How to Send a Plesk API PHP Command

How to Send a Plesk API PHP Command thumbnail
PHP requests through Plesk API protocol are processed as XML files.

Plesk is an application programming interface (API) protocol that provides XML-based support and interaction with web programming technologies, such as PHP. The Plesk API RPC protocol is used to call various functions remotely. The information Plesk gathers from those functions come back in specifically formatted packets, but most of the returned packets are in XML format. Since Plesk is compatible with PHP, many developers use it as an API protocol for diverse projects.

Instructions

    • 1

      Use the code below to define the host, port and path of your PHP server. In this project, a CURL engine -- a free and open client-side URL transfer library -- is used since it is compatible with PHP 4.0.2 and higher version.

      define ('HOST', '10.58.97.81');

      define ('PORT', 8443);

      define ('PATH', 'enterprise/control/agent.php');

      $URL = 'https://' . HOST . ':' . PORT . '/' . PATH;

    • 2

      Confirm the array of your Plesk API header elements to make sure the output is in XML format, so it is PHP-supported, as shown below:

      $headers = array(

      'HTTP_AUTH_LOGIN: admin',

      'HTTP_AUTH_PASSWD: setup',

      'Content-Type: text/xml'

      );

    • 3

      Input the following code to initialize the CURL engine and to make sure that all required parameters are set for best output:

      // initialize the curl engine

      $ch = curl_init();

      // set the curl options:

      // do not check the name of SSL certificate of the remote server

      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

      // do not check up the remote server certificate

      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

      // pass in the header elements

      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

      // pass in the URL of the target server

      curl_setopt($ch, CURLOPT_URL, $URL);

    • 4

      Input the following code to tell the CURL engine to process the transfer and deliver the request via Plesk API protocol:

      // tell CURL to return the result rather than to load it to the browser

      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

      // pass in the packet to deliver

      curl_setopt($ch, CURLOPT_POSTFIELDS, $packet);

      // perform the CURL request and return the result

      $retval = curl_exec($ch);

      // close the CURL session

      curl_close($ch);

Tips & Warnings

  • The complete parameters are found at SWSoft website for your reference. Apply them thoroughly to complete your project. Also, join discussion forums to seek advice from experienced PHP users.

Related Searches:

References

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images

Comments

Related Ads

Featured