Sameh Yassin
Sameh Yassin

Reputation: 464

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

Upvotes: 1

Views: 313

Answers (2)

Sameh Yassin
Sameh Yassin

Reputation: 464

[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>

Upvotes: 1

James Thomas
James Thomas

Reputation: 4339

The HttpRequest module is an optional PEAR package. This won't be included by default in your PHP environment. Looking at this thread, there a number of ways to get optional modules installed.

The simplest is to use Composer.

You can use Composer to install them. Often times Pear modules are also listed in the Composer repositories, so you can install them directly with Composer instead. If not, you can also use Composer to install Pear modules, which will pull them from the Pear repo.

PHP buildpack documentation has details about configuring Composer with your application.

Upvotes: 1

Related Questions