is_wp_error and wp_remote_get cURL error 28



我正在使用以下代码。假设$url类似https://example.com/cron/cron.php.我收到了失败消息,但它实际上是有效的,因为在链接的脚本中,我发送了一封电子邮件,而我正在接收电子邮件。

那么,如果它有效,那么为什么is_wp_error会触发呢?

if (is_wp_error($wp_remote_get = wp_remote_get($url))) {
echo "Failed to get script. Error: " . $wp_remote_get->get_error_message() . " Exiting...";
exit;
}

收到错误:Failed to get script. Error: cURL error 28: Operation timed out after 5004 milliseconds with 0 out of -1 bytes received

所以这是一个有点愚蠢的问题。wp_remote_get检索http响应,但我认为它只是访问url来运行脚本。该脚本需要一段时间才能完成,因此它必须在时间限制内运行,这似乎是错误消息所暗示的。

我只是使用wp_redirect来解决这个问题。如果我能找到一种不用重定向就能运行另一个脚本的方法,那就太好了。

最新更新