PHP · 2026年2月22日

【PHP】cURLのデバッグコード

$c = curl_init();
curl_setopt($c, CURLOPT_URL, “https://rc.aaa.xxx.y.co.jp”);

…(省略)

// SSL通信
$handle_err = fopen(“/tmp/curl_s.log”, “w+”);
curl_setopt($c, CURLOPT_STDERR, $handle_err);

// ヘッダ部分
$handle_header = fopen(“/tmp/curl_h.log”, “w+”);
curl_setopt($c, CURLOPT_WRITEHEADER, $handle_header);

// レスポンス結果
$handle_file = fopen(“/tmp/curl.log”, “w+”);
curl_setopt($c, CURLOPT_FILE, $handle_file);

…(省略)

$response = curl_exec($c);