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 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?