Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Non-blocking PHP/Perl request to cPanel

Discussion in 'cPanel Developers' started by chicagosky, Dec 9, 2014.

  1. chicagosky

    chicagosky Registered

    Joined:
    Dec 8, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    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
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,711
    Likes Received:
    1,794
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice