Reputation: 464
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:
Upvotes: 1
Views: 313
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:
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"
}
Install the package using composer locally
php composer.phar install
Now, everything is ready we should push the whole application back to bluemix:
Login to blue mix using username and password
bluemix login
connect to IBM blue mix
bluemix api https://api.ng.bluemix.net
Push the application, where matches your application name
cf push <app_name>
Upvotes: 1
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