在AWS EC2实例空卷曲在PHP返回 [英] Curl in PHP returns null on AWS EC2 instance

查看:187
本文介绍了在AWS EC2实例空卷曲在PHP返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有AWS EC2,Apache服务器设置。所有的网页都工作,除了无论我起诉卷曲两个地方。继指针按这个问题在网上搜索,这是否按预期工作:

I have AWS EC2 , Apache server setup. All website pages are working except for two places whereever I sued CURL. Following pointers as per this issue search online, which are working as expected:

卷曲显示了向上的phpinfo()。 curl命令可以访问和运行翻过。 Apache2中确实有卷曲安装。 从CLI curl命令工作正常。 (卷曲的http://本地主机并卷曲www.google.com)这两个正在

CURL is showing up in phpinfo(). CURL command is accessible and running accross. Apache2 does have CURL installed. curl command from CLI is working fine. (curl http://localhost and curl www.google.com) both are working.

当我跑到下面的函数,在浏览器$网址中运行时的URL,返回数据符合市场预期。但是,当我从PHP运行,没有回声的命令以往任何时候都返回一个值。此外,价值观似乎为空。

When I ran following function, url when run in browser $url, returns data as expected. But when I run from PHP, none of the echo commands ever returned a values. Further, values seem to be null.

功能get_patients(){     $主机=的file_get_contents(' http://169.254.169.254/latest/meta-data/public -HostName ');     $ URL = $主机名'/文件夹1 / app1.php吗?';

function get_patients(){ $hostname = file_get_contents('http://169.254.169.254/latest/meta-data/public-hostname'); $url = $hostname.'/folder1/app1.php?all';

//echo $url;

///$url .= urlencode($query);//.'&key='.$key;

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

//echo $curl;

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT , 400);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);

$data = curl_exec($curl);

curl_close($curl);

//decoding request

$result = json_decode($data, true);

//print_r( $data);

return $result;
}

这是第一个函数,在此基础上大多数API都依赖。这上面的PHP文件是无功/网络/ HTML /文件夹1。当我访问了主要的API,我想在浏览器访问, $主机名。'/文件夹1 / app1.php?所有的',不作为托管本地Apache服务器,甚至远程域上的返回数据主机服务器。它只是不工作AWS EC2。

This is the first function, based on which most of APIs are dependent on. This above php file is in var/www/html/folder1. when I access the main API that I am trying to access in browser, $hostname.'/folder1/app1.php?all', does return data as hosted on a local apache server and even remote domain host server as well. Its just not working with AWS EC2.

推荐答案

感谢吨答复。当连续疑难解答我得到这个固定的。需要配置的改变在php.ini的Apache服务器的配置进行修改,只要确保设置和版本服务器相同的两个PHP5和Apache2的文件夹。此外PHP5必须安装PHP5-libcurl的,它已经在那里我的服务器上。谢谢大家迅速的反应。

Thanks ton for reply. Upon continuous troubleshooting I got this fixed. Needed a change in configuration to be modified in php.ini in apache server configuration, just make sure settings and versions are same in both PHP5 as well as Apache2 folders on server. Also PHP5 MUST have PHP5-libcurl installed, which was already there on my server. Thank you everyone for swift response.

这篇关于在AWS EC2实例空卷曲在PHP返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆