Search code examples
woocommercepaypal-ipn

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


In my theme's functions.php, I am adding an action for the event woocommerce_order_status_changed. In this action, I send mails, create files and upload them to an ftp server.

When I get a PayPal IPN, it seems that my function is not terminating and I think it's because PayPal is not waiting until my script is finished.

Does anybody know if that is true or if I can increase the waiting time for PayPal IPNs?

If not, where should I place longer codeblocks which need do be executed after an IPN?


Solution

  • Taking too long receiving a 3rd party request certainly sounds like bad style.

    Here’s what appears to be the 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.

    You could kick off a separate process that runs in the background to take care of all the rest you need to do.

    How to do that depends on your environment, see e.g. php execute a background process.

    Note that you’ll have to pass all the info to the script that is necessary to do what it needs to do (transaction ID etc.) That info is not automatically passed to a PHP script you start using exec() or through other means.