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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀