在BlueMix的php环境中使用curl_init()时出错


Error using curl_init() in php environment on BlueMix

我在Bluemix上使用PHP运行时。在我的解决方案中,我需要调用Internet上端口3000上可用的外部API。

我使用curl来管理API调用,使用以下代码:

$endPoint="http://".$this->server.":".$this->port.$endPoint;
$session = curl_init($endPoint);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($session);

在Bluemix日志中,我发现以下错误:

Got error 'PHP message: PHP Fatal error: Call to undefined function
curl_init() in /home/vcap/app/htdocs/include/service.php on line 50'n',
referer: http://m2msite.mybluemix.net/login.php

在我的运行时中,它似乎不是一个定义的curl库
我没有找到任何关于如何在Bluemix运行时中定义curl库的文档。

有人能帮助我以正确的方式配置运行时吗?

提前感谢

我找到了解决方案。

在项目根目录下,我创建了一个目录.bp-config
在目录中,我创建了一个文件option.json,其中包含以下内容:

{
    "PHP_EXTENSIONS": ["mysqli","curl"]
}

mysqli用于mysql库,而curl则用于curl库。

所以现在我可以在我的项目中使用curl库了

是否有人链接到有关此配置步骤的完整文档?

Ciao

与PHP构建包相关的此类配置的完整文档可以在这里找到

https://docs.cloudfoundry.org/buildpacks/php/gsg-php-config.html