Search code examples
phpmultithreadingapachegoogle-checkout

start a second instance from PHP, and allow suspension with sleep, without generating the TIMEOUT error?


Everything Cut Short: Need to execute a function after around 5 minutes after a request sent by Google Checkout's Notification Service.

Why: The History API requires the transaction to be atleast 5 min old to work.

What has been tried, suspending teh function by sleep, but it generates a TIMEOUT error at google's end.

Main Concern: The function must run, even if the user navigates away from page, reloads the page, or closes his/her browser or logout from the Site..

Tried, Google but not of much use.. Any Ideas??


Solution

  • This sounds like a job for cron. Here's a possible implementation outline:

    1. When Google sends a Checkout Notification, record the notifcation details and timestamp in your database.
    2. Setup a script to be run by cron. The script will check the database for new Checkout Notifications that are at least 5 minutes old.
    3. The script will then access the History API for those matching records and then mark those records in the database so that they won't be accessed again the next time the cron job runs.

    The cron job can be set to run at any interval you like. The lower the interval, the more quickly History API requests will be made as Checkout Notifications hit the 5 minute age. Your cron script can record the result of the History API request in your database so that your web interface can retrieve it and show it to the user.