在 Bluemix 上使用 PHP 发送 HTTP 请求
Sending an HTTP request using PHP on Bluemix
我在 www.bluemix.net 上有一个使用 PHP 的项目。我尝试发送一个 HTTP 请求,如下面的代码所示,但我从未到达 {echo "b";} 命令。我认为在 Bluemix 上使用 PHP 时,默认情况下未启用 HTTP 请求。
<?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);
?>
有没有人以这种方式使用 Bluemix 并且在使用 HTTP 请求时遇到同样的问题?
提示:
项目结构如下所示:
HttpRequest module is an optional PEAR package. This won't be included by default in your PHP environment. Looking at this thread,有很多方法可以安装可选模块。
最简单的就是使用 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 包含有关使用您的应用程序配置 Composer 的详细信息。
[已解决]问题现在已经解决了,我只需要将应用程序下载到我的电脑上,然后在本地安装composer,然后将整个东西推送到 bluemix。
我认为这不是最好的方式,因为我更喜欢直接在云端编码。无论如何,我将总结可用于 运行 HttpRequest with IBM bluemix 的步骤:
- 获取 www.bluemix.net
的用户名和密码
- 创建 space 和应用程序(通过命令行或用户界面)
- 按照文档中的说明安装作曲家here
转到本地计算机,在应用程序文件夹中,将文件 composer.json 修改为包括任何 http 包。对我来说,我使用了 php-curl,所以文件看起来像
{
"require": {
"php-curl-class/php-curl-class":"*"
}
"minimum-stability": "dev"
}
在本地使用 composer 安装包
php composer.phar install
Now, everything is ready we should push the whole application back to
bluemix:
使用用户名和密码登录 blue mix
bluemix login
连接到 IBM blue mix
bluemix api https://api.ng.bluemix.net
推送应用,匹配你的应用名称
cf push <app_name>
我在 www.bluemix.net 上有一个使用 PHP 的项目。我尝试发送一个 HTTP 请求,如下面的代码所示,但我从未到达 {echo "b";} 命令。我认为在 Bluemix 上使用 PHP 时,默认情况下未启用 HTTP 请求。
<?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);
?>
有没有人以这种方式使用 Bluemix 并且在使用 HTTP 请求时遇到同样的问题?
提示:
项目结构如下所示:
HttpRequest module is an optional PEAR package. This won't be included by default in your PHP environment. Looking at this thread,有很多方法可以安装可选模块。
最简单的就是使用 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 包含有关使用您的应用程序配置 Composer 的详细信息。
[已解决]问题现在已经解决了,我只需要将应用程序下载到我的电脑上,然后在本地安装composer,然后将整个东西推送到 bluemix。
我认为这不是最好的方式,因为我更喜欢直接在云端编码。无论如何,我将总结可用于 运行 HttpRequest with IBM bluemix 的步骤:
- 获取 www.bluemix.net 的用户名和密码
- 创建 space 和应用程序(通过命令行或用户界面)
- 按照文档中的说明安装作曲家here
转到本地计算机,在应用程序文件夹中,将文件 composer.json 修改为包括任何 http 包。对我来说,我使用了 php-curl,所以文件看起来像
{
"require": { "php-curl-class/php-curl-class":"*" } "minimum-stability": "dev"
}
在本地使用 composer 安装包
php composer.phar install
Now, everything is ready we should push the whole application back to bluemix:
使用用户名和密码登录 blue mix
bluemix login
连接到 IBM blue mix
bluemix api https://api.ng.bluemix.net
推送应用,匹配你的应用名称
cf push <app_name>