dongmu2517 2017-10-25 01:35
浏览 105
已采纳

如何调试PHP cURL不会触发请求?

Environment

  • PHP Version : PHP 5.6.21

  • cURL Version : curl 7.29.0

  • Web Server : Nginx

  • Linux : Cent OS


Description

I have this CURL in PHP.

$headers = array(
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Basic " . $auth_code
);

$data = 'grant_type=authorization_code&code='.$code;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$AUTH_TOKEN_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_USERAGENT,'php');
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$info = curl_getinfo($ch);
$result = curl_exec($ch);

I did a Wireshark capture, I don't any GET/POST requests initiating.

What could possibly prevent it?

What else should I look into ?


I've tried print out these 2 values

**dd($ch);**

I got  

"ch" => curl resource @10 ▼
    url: "https://www.web.com/oauth"
    content_type: null
    http_code: 0
    header_size: 0
    request_size: 0
    filetime: -1
    ssl_verify_result: 0
    redirect_count: 0
    total_time: 0.004216
    namelookup_time: 0.004148
    connect_time: 0.113475
    pretransfer_time: 0.0
    size_upload: 0.0
    size_download: 0.0
    speed_download: 0.0
    speed_upload: 0.0
    download_content_length: -1.0
    upload_content_length: -1.0
    starttransfer_time: 0.0
    redirect_time: 0.0
    redirect_url: ""
    primary_ip: "8.8.8.8"
    certinfo: []
    primary_port: 443
    local_ip: "10.0.129.127"
    local_port: 56907
}


**dd($info);** 

I got 

"info" => array:26 [▼
"url" => "https://www.web.com/oauth"
"content_type" => null
"http_code" => 0
"header_size" => 0
"request_size" => 0
"filetime" => 0
"ssl_verify_result" => 0
"redirect_count" => 0
"total_time" => 0.0
"namelookup_time" => 0.0
"connect_time" => 0.0
"pretransfer_time" => 0.0
"size_upload" => 0.0
"size_download" => 0.0
"speed_download" => 0.0
"speed_upload" => 0.0
"download_content_length" => -1.0
"upload_content_length" => -1.0
"starttransfer_time" => 0.0
"redirect_time" => 0.0
"redirect_url" => ""
"primary_ip" => ""
"certinfo" => []
"primary_port" => 0
"local_ip" => ""
"local_port" => 0
]

nothing seems to use in there.


Questions

How would one go about and debug this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!

  • 写回答

2条回答 默认 最新

  • duandun2218 2017-10-25 01:42
    关注

    SELinux is preventing the httpd process from making a network connection.

    setsebool -P httpd_can_network_connect 1
    

    See the httpd_selinux(8) man page for details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计
  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低