如何找出 cURL 挂起且无响应的原因?

2024-04-13php开发问题
1

本文介绍了如何找出 cURL 挂起且无响应的原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试查找 PHP 中的 cURL 调用问题.它在我们的测试环境中运行良好,但在我们的生产环境中却不行.当我尝试执行 cURL 函数时,它只是挂起并且永远不会响应.我试过从命令行建立一个 cURL 连接,同样的事情发生了.

I am trying to track down an issue with a cURL call in PHP. It works fine in our test environment, but not in our production environment. When I try to execute the cURL function, it just hangs and never ever responds. I have tried making a cURL connection from the command line and the same thing happens.

我想知道 cURL 是否记录了某处正在发生的事情,因为我无法弄清楚在命令搅动和搅动期间发生了什么.有谁知道是否有记录那里发生的事情的日志?

I'm wondering if cURL logs what is happening somewhere, because I can't figure out what is happening during the time the command is churning and churning. Does anyone know if there is a log that tracks what is happening there?

我认为这是连接问题,但我们的 IT 人员坚持认为我应该能够毫无问题地访问它.有任何想法吗?我正在运行 CentOS 和 PHP 5.1.

I think it is connectivity issues, but our IT guy insists I should be able to access it without a problem. Any ideas? I'm running CentOS and PHP 5.1.

更新:使用详细模式时,我收到错误 28Connect() Timed Out".我尝试将超时时间延长到 100 秒,并将 max-redirs 限制为 5,没有变化.我尝试ping盒子,也有超时.因此,我将把它提交给 IT 部门,看看他们是否会再看一遍.感谢所有的帮助,希望我能在半小时后回来告诉他们这是他们的问题.

Updates: Using verbose mode, I've gotten an error 28 "Connect() Timed Out". I tried extending the timeout to 100 seconds, and limiting the max-redirs to 5, no change. I tried pinging the box, and also got a timeout. So I'm going to present this back to IT and see if they will look at it again. Thanks for all the help, hopefully I'll be back in a half-hour with news that it was their problem.

更新 2: 原来我的机器正在使用外部 IP 地址解析服务器名称.当 IT 给我内部 IP 地址并在 cURL 调用中替换它时,一切正常.感谢大家的帮助.

Update 2: Turns out my box was resolving the server name with the external IP address. When IT gave me the internal IP address and I replaced it in the cURL call, everything worked great. Thanks for all the help everybody.

推荐答案

在你的 php 中,你可以设置 CURLOPT_VERBOSE 变量:

In your php, you can set the CURLOPT_VERBOSE variable:

curl_setopt($curl, CURLOPT_VERBOSE, TRUE);

然后记录到 STDERR,或使用 CURLOPT_STDERR 指定的文件(接受文件指针):

This then logs to STDERR, or to the file specified using CURLOPT_STDERR (which takes a file pointer):

curl_setopt($curl, CURLOPT_STDERR, $fp);

从命令行,您可以使用以下开关:

From the command line, you can use the following switches:

  • --verbose 向命令行报告更多信息
  • --trace <file>--trace-ascii <file> 跟踪到文件
  • --verbose to report more info to the command line
  • --trace <file> or --trace-ascii <file> to trace to a file

您可以使用 --trace-time 将时间戳添加到详细/文件输出

You can use --trace-time to prepend time stamps to verbose/file outputs

这篇关于如何找出 cURL 挂起且无响应的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17