Page 1 of 1

Calling WebAPI in PHP via cURL

Posted: Fri Dec 15, 2017 4:24 pm
by loï6183
Hi !

I want to create a PHP script to automatically deploy my application, but I don't manage to make the WebAPI work... Everytime I try, either I receive the "login" page of the UI or I receive a "connexion refused". I tried calling a simple route with no parameters (jobqueueStatistics) but I can't make it work, and the documentation isn't very helpful...
I use Zend Server Version 6.3.0, Professional Edition.

Here is my PHP function :

Code: Select all

function callAPI($action)
        $ch         = curl_init();
        $path      = '/ZendServer/Api/' . $action; //I'm not even sure about the path
        $host      = $_SERVER['HTTP_HOST'];
        $time      = strftime('%a, %d %b %Y %H:%I:%S') . ' GMT';
        $userAgent = $_SERVER['HTTP_USER_AGENT'];

        curl_setopt($ch, CURLOPT_URL, 'http://xxx.yyy.zzz:10081' . $path); //Returns the login page with port 10081,cURL fails with port 10083
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'X-Zend-Signature: developer;' . generateRequestSignature($host, $path, $time, $userAgent, 'MY_KEY_FOR_DEVELOPER_FOUND_IN_THE_UI'),
            'Date: ' . $time,
            'User-Agent: ' . $userAgent,
            'Host: ' . $host,
        $output = curl_exec($ch);

        return $output;
And I call it with

Code: Select all

for the moment.

Do I do this wrong ? Is there something to configure beforehand ? I'm a bit lost...

Re: Calling WebAPI in PHP via cURL

Posted: Mon Apr 09, 2018 4:48 am
by jenn2321
Hi,I have read through some similar topics! However, your post has given me a very special impression, unlike other posts. I hope you continue to have valuable articles like this or more to share with everyone.

Re: Calling WebAPI in PHP via cURL

Posted: Tue May 08, 2018 9:59 am
by mark7626
Hi, your blog is truly flawless and unique. Good content, but it would be better if in future you can talk about more about this subject. Really very perfect your article and blog post.

Re: Calling WebAPI in PHP via cURL

Posted: Thu May 17, 2018 5:21 pm
by clarkphp

You may wish to use the DeploymentHelper, or the ZendServerSDK, both of which make it easier to deploy applications via the WebAPI. The ZendServerSDK can also be used to access other WebAPI methods besides deployment, from the command line.

Zend Server 6.3 is quite old, indeed, and is no longer supported. I strongly suggest you upgrade to a current version (Zend Server 8.5 for PHP 5.6, or Zend Server 9.1 for PHP 7.1).

Clark Everetts
Zend Professional Services Consultant
Rogue Wave Software