簡體   English   中英

如何調試不觸發請求的PHP cURL?

[英]How can I debug PHP cURL not triggering a request?

環境

  • PHP版本: PHP 5.6.21

  • cURL版本: curl 7.29.0

  • 網頁伺服器: Nginx

  • Linux: Cent OS


描述

我在PHP中有這個CURL。

$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);

我進行了Wireshark捕獲, 沒有啟動任何GET / POST請求。

有什么可能阻止它?

我還應該考慮什么?


我嘗試打印出這兩個值

**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
]

那里似乎什么也沒用。


問題

人們將如何進行進一步調試?


目前,我願意接受任何建議。

任何提示/建議/幫助將不勝感激!

SELinux阻止了httpd進程建立網絡連接。

setsebool -P httpd_can_network_connect 1

有關詳細信息,請參見httpd_selinux(8)手冊頁。

如果您需要進一步調查,可以嘗試使用strace

如果例如通過訪問頁面“ /mycode.php”觸發此代碼:

strace -tt -e trace=sendto,connect,open,write,read php /path/to/your/app/mycode.php

如果您的代碼是通過框架執行的,或者通過諸如index.php之類的入口點處理的:

HTTP_HOST=www.yourdomain.com REQUEST_URI=/mycode.php strace -tt -e trace=sendto,connect,open,write,read php /path/to/your/app/index.php

這樣的輸出應該能夠使您指出問題的根源(例如,某些文件未打開,過程未啟動)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM