Non-blocking PHP/Perl request to cPanel

chicagosky

Registered
Dec 8, 2014
2
0
1
cPanel Access Level
Website Owner
Hello

Thanks in advance for taking time to read my question. I have a problem integrating the cPanel API with PHP. I have a web application that is built in PHP and invokes cPanel API to create an email forwarding address when the user completes the registration process. I have downloaded the XMLAPI library provided by cPanel team and this works perfectly. My code to call the XMLAPI is below for reference.

Code:
$xmlapi->api2_query(Configure::read($cpanelUser), 'Email', 'addforward', array(
							'email' => $username, 
							'fwdopt' => 'pipe', 
							'pipefwd' => Configure::read('CPanel.pipe_fwd'), 
							'domain' => Configure::read('www.mydomain.com')
							)
						);
This above method invokes a method which has the following code -

Code:
private function curl_query( $url, $postdata, $authstr ) {
  $curl = curl_init();
		
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  // Return contents of transfer on curl_exec
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  // Allow self-signed certs
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  // Set the URL
  curl_setopt($curl, CURLOPT_URL, $url);
  // Increase buffer size to avoid "funny output" exception
  curl_setopt($curl, CURLOPT_BUFFERSIZE, 131072);
  .....
  .....
}
The problem I have is that this method is 'blocking' in nature - that is the PHP script is stuck waiting for a response from this method before proceeding ahead (either this or it is waiting for a timeout scenario). Is there some recommendation / suggestion for a way to invoke a non-blocking method request from PHP.

I am also open to have a PERL script execute - but need suggestion and guidance on how to create a non-blocking request from PHP.

Thanks in advance
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello :)

You may receive more user-input on this type of question at a forum where discussions of PHP programming occur. Most of the feedback you will receive here involves the cPanel API itself.

Thank you.