我的脚本是否需要很长时间以致于导致 PayPal IPN 超时?

Does my script take so long it causes a timeout with PayPal IPN?

在我的主题 functions.php 中,我正在为事件 woocommerce_order_status_changed 添加一个动作。 在此操作中,我发送邮件、创建文件并将它们上传到 ftp 服务器。

当我获得 PayPal IPN 时,我的功能似乎没有终止,我认为这是因为 PayPal 没有等到我的脚本完成。

有人知道这是不是真的,或者我是否可以增加 PayPal IPN 的等待时间?

如果不是,我应该在哪里放置需要在 IPN 之后执行的较长代码块?

接收第 3 方请求的时间太长听起来确实很糟糕。

这似乎是 official timeout guidelines:

PayPal's Instant Payment Notification (IPN) system expects your web server to send an HTTP 200 response when the IPN is sent to your IPN script.

If your server does not respond after a certain amount of time, the IPN system then re-posts the IPN to your script.

The amount of time between each re-post doubles each time: 10 seconds, 20 seconds, 40 seconds, 80 seconds, etc., up to a maximum of 24 hours. The IPN system stops re-posting when PayPal receives a basic HTTP "200 OK" response from your web server or when approximately four days have passed since the initial post.

Note: This functionality applies to both Sandbox and Live accounts.

您可以启动一个在后台运行的单独进程来处理您需要做的所有其他工作。

如何做到这一点取决于您的环境,例如参见php execute a background process.

请注意,您必须将所有信息传递给执行所需操作所必需的脚本(交易 ID 等)。该信息不会自动传递给您的 PHP 脚本开始使用 exec() 或通过其他方式。