Search code examples
phphttprequestibm-cloud

Sending an HTTP request using PHP on Bluemix


I have a project on www.bluemix.net that uses PHP. I try to send an HTTP request as shown in the code below, but I never reach the {echo "b";} command. I think that the HTTP request is not enabled, by default, when PHP is used on Bluemix.

<?php
error_reporting(E_ALL);

echo "a";
$request = new HttpRequest();    // I never pass this line
echo "b";
$request->setUrl('https://stream.watsonplatform.net/speech-to-text/api/v1/recognize');
$request->setMethod(HTTP_METH_POST);

?>

Has anyone used Bluemix this way and had the same issue with using an HTTP request?

Hint: The project structure looks as follows: enter image description here


Solution

  • [SOLVED] The issue is solved now, all I needed was to download the application to my computer, and install composer locally, followed by pushing the whole thing to bluemix.

    I believe that is not the best way, because I prefer to code directly on the cloud. Whatsoever, I'll summarize the steps that can be used to run HttpRequest with IBM bluemix:

    1. Get a user name and password for www.bluemix.net
    2. Create a space, and an application (by command line or by user interface)
    3. Install composer as described in the documentation here
    4. Go local to your computer, inside your application folder, modify the file composer.json to include any http package. For me, I used php-curl, so the file looks like

      {

          "require": {
              "php-curl-class/php-curl-class":"*"
          }
         "minimum-stability": "dev"
      

      }

    5. Install the package using composer locally

      php composer.phar install

    Now, everything is ready we should push the whole application back to bluemix:

    1. Login to blue mix using username and password

      bluemix login

    2. connect to IBM blue mix

      bluemix api https://api.ng.bluemix.net

    3. Push the application, where matches your application name

      cf push <app_name>