Page 1 of 1
Ack Incoming POST and then process
Posted: Sat Jul 24, 2010 1:25 am
by rocksolidhq
Hey,
i have a PHP app that ties into a couple of other systems. One is a payment gateway and the other provides a set of proprietary functions. The problem that i have is that i am caught in the middle and need to compensate for potential timing issues. The payment gateway, upon processing a payment, returns the result via HTTP POST. i recieve this info and if the payment was successful then i call a function on the other proprietary system to process the order. The problem is that the proprietary system sometimes takes 20 or 30 seconds to respond but the payment gateway tosses an ugly error if the page that it POSTs to doesn't complete loading within 10 seconds. It seems that the payment gateway isn't happy until my POST recieving page is finished loading but it can't finish loading until i get a response from the proprietary system.
So the question is this: is there a way to acknowledge the HTTP POST received from the payment gateway and _then_ continue with the processing? i've tossed around the idea of having a simple PHP file to receive the POST and then redirect to the processing page. Is that the best solution? Is there a way to call a function (or seperate PHP file) that would allow the rest of the page to load...nah that doesn't even make sense to me when i type it.
open to some suggestions.
thanks in advance,
dean
Re: Ack Incoming POST and then process
Posted: Sat Jul 24, 2010 2:38 am
by Gargoyle
you could send a "HTTP OK" header before the function call which may do the job.
other than that, I would rather target the 20-30 seconds delay. this is not normal and timeouts are there for a reason. also, what are you going to do if you sent "ok" to the payment gateway and then you don't get the other server to respond at all?
no, fix the 20 second server, don't start fiddling with something that critical.
Re: Ack Incoming POST and then process
Posted: Sat Jul 24, 2010 9:24 am
by rocksolidhq
Hey Gargoyle,
Yeah i'd love to get the 20-30 delay sorted out but it is introduced by the proprietary system and they're not budging.

it only happens once in a while but it still needs to be addressed. You've nailed the second phase of my problem solving on the head though. There are indeed times that i get no response at all and PHP is happy to wait and wait and wait until the timeout has been reached at which point i get the PHP timeout error or stack overflows.
So to respond to your message, i'd love to fix the delay but it's out of my reach so i have to compensate for it, and, i just don't know what to do with PHP timeout/stack errors. i know that it's something that i'll have to deal with, but figured i'd satisfy the payment gateway first and the solution to the second problem may present itself during that process. i guess it would have been more efficient to mention it in the original message so thanks for picking up on it.
i've put the header in and we'll see if that satisfies the payment gateway. Due to the intermittent nature of the delay's i won't know if that fixes it for a few days.
As for dealing with a non-response...any suggestions? i've done a bit of looking but honestly not much yet. The end of the project is now in sight though and this is certainly in the way.
thanks again
Re: Ack Incoming POST and then process
Posted: Sat Jul 24, 2010 12:06 pm
by Weirdan
There a number of possibilities to implement background processing in php, all of them would allow you to request your processing to be done by some other script allowing your receiving script to respond to the payment gateway request.
- run a command line script via system() that would do the heavy lifting:
Code: Select all
system("/path/to/nohup /path/to/php /path/to/script 2>&1 > /path/to/script/log")
- fire up Gearman job in background
- use Zend's job queue
- implement you own (it would need some storage to store requests and continuously running daemon in the background that would fetch requests from the storage and process them)
Re: Ack Incoming POST and then process
Posted: Sat Jul 24, 2010 5:42 pm
by rocksolidhq
Hey Weirdan,
Good ideas but unfortunately it won't work in this situation. i need the reply from the proprietary system in order to complete the transaction and display the final page. Basically the final page is a confirmation that includes the result of the payment as well as the result of the proprietary system's function call.
thanks though. it has definately got the wheels spinning on different aspects of this project that may be better served by moving some of the non-time sensitive tasks to the background.
Re: Ack Incoming POST and then process
Posted: Sat Jul 24, 2010 7:32 pm
by Weirdan
Hmm, I thought that processing page is accessed by the payment gateway, but now you're saying you need to display a page... I suppose display it to the customer, right? Can you explain the sequence of calls you have between those different systems?
Re: Ack Incoming POST and then process
Posted: Sat Jul 24, 2010 10:34 pm
by rocksolidhq
Hey,
Let's see if can explain the sequence properly and completely this time...there are 4 pages to the sequence altogether including the payment page which is on the payment gateway's system. My PHP presents 3 pages as follows:
Page 1 - form input - customer inputs the details of the order that they wish to place
Page 2 - Confirmation and Payment Selection - customer confirms the details of the order and selects a payment method.
Upon clicking the Page 2 submit button the customer is taken to the payment gateway's payment page where the customer
enters payment details. The payment gateway system authorizes the payment, or not and redirects back to my PHP file.
Page 3 - Results and order details - Once the customer has submitted their payment details on the payment gateway's page they are
redirected back my system and if the payment was successful then i process the order using a function on the proprietary
system. This is where the delay comes in; waiting for the response that the order has been placed with the proprietary
system and i need the order number from the proprietary system (which indicates that the order was placed successfully)
before displaying the results as it includes payment confirmation numbers, order details, and the order number.
these three pages are built in one PHP file and the _POST indexes are used to keep track of where we are and where we need to go next.
When the customer is redirected back to my PHP file it heads to the third page, the _POST detail is inspected for a payment result, and if the payment was successful then the order is placed and at that point the details can be displayed.
In _very_ simplified terms:
Code: Select all
if($_SERVER['REQUEST_METHOD'] == 'GET')
page1();
elseif ($_POST['page'] == "page2")
page2();
else
page3();
...
function page3()
{
//declare the variables
$orderDetails = array();
// if the payment result is > 0 then it was succesful and we can place the order
if ($_POST['payment_auth_result'])
{
// place the order using the _POST indexes which contain the relavent order details and put the results into the array
// this is the function that can take 20-30 seconds before i have a response.
$orderDetails = placeOrder($_POST);
// if our orderNumber is > 0 then the order was also successful and we can display the results and details.
if ($orderDetails['orderNumber'])
{
print "your order has been successfully placed. Your order number is " . $orderDetails['orderNumber'] . ".<br />";
print "Your invoice number is " . $_POST['payment_inv_num'];
}
}
else
print "your payment was not successful.";
}
thanks for your patience.
Re: Ack Incoming POST and then process
Posted: Sun Jul 25, 2010 8:01 am
by rocksolidhq
Hey,
forgot to reiterate the goal here. There are two:
First, if the payment gateway does not see page3 load within 10 seconds it tosses a nasty error so we need to send back some sort of acknowledgement that the POST data that it is sending has been received (which it has) before the page has completely loaded. Hopefully Gargoyle's header suggestion will satisfy this.
Second, if the proprietary system has lost it's brain and never responds to the order request then PHP either times out or tosses it's stack (stack overflow). How do we limit the time that we wait for a response from the proprietary system's function call (placeOrder() in the simplified version) and if we reach that limit present a more graceful and informative error message of our own design.
thanks again.
Re: Ack Incoming POST and then process
Posted: Mon Jul 26, 2010 4:13 am
by Gargoyle
Code: Select all
elseif ($_POST['page'] == "page2")
this will throw a warning if $_POST['page'] is not defined.
other than that and if I understand you right, page3 is called when the payment has been received and your problem is that this 3rd party software takes ages to actually confirm that the order has been entered into theri system. in this case, you could first store the order information in a database table and display a "we're processing your order, please wait" website, which you reload all five seconds while a cronjob in the background deals with the 3rd party software and will mark the order as ok as soon as the response has come in. upon that, you can redirect the user to the real confirmation page.
I'd still rather target the 3rd party system because a 20 or 30 second delay is just not acceptable.