Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger / Delay PHP script processing

Currently I have a script which processes orders after someone is directed to a payment processor.

The payment processor will occasionally send two (or more) responses to my site (usually within a minute of the first response).
I have contacted the payment processor about the issue; they don't see this as an issue with their system and say my script should take into account any extra responses and only listen to the last one sent.

On multiple response orders, the first response is successful, and so the order is processed when this response comes in.
If a 2nd response comes, its usually about 30 seconds later with an error response and I cancel the order.
The problem is that I have already sent out a "thank you for your order" email to the customer from the first response, which obviously isn't ideal.

Is there a way to trigger a separate script to run a few minutes after the order is processed? i.e to check if the order is still valid a couple of minutes after the original order and send the email out

I was thinking a cron job which runs every minute, but surely this would be overkill since the script only needs to run if an order has been placed?

like image 711
Nick Avatar asked Jul 11 '26 19:07

Nick


2 Answers

You can start background job using shell_exec("/usr/bin/php /path/to/test.php ".($orderId)." &"); with 3 minute delay at the start (sleep(180)); and then execute code to check status of the order. $argv[2] should contain your orderId number.

like image 135
Arkadiusz 'flies' Rzadkowolski Avatar answered Jul 13 '26 12:07

Arkadiusz 'flies' Rzadkowolski


Heres what you can do

after the first response is recieved, make your script wait for some time, say 1 minute using the sleep() function

http://php.net/manual/en/function.sleep.php

like image 22
geekman Avatar answered Jul 13 '26 11:07

geekman