I am confused what approach to take when updating a status e.g delivery on our client's system. On normal process, they provide us URL where we will post back the delivery data.
The problem now is what if we update the delivery data, then we'll have to notify our client's system too so the change of delivery status on their system happens real time instead of the cron job (check delivery status).
Should this be a
header('Location:http://path/to/client/parse_update_delivery_status.php');
once all the updating on our system is done or a
cURL.... //http post to client's url for updating delivery status on their system based on what we passed here
approach?
I'd really appreciate your input! :) Thanks!
I'm pretty certain that would have to be done with cURL, and at the very least would work much better using curl. Does parse_update_delivery_status.php receive data from an HTTP POST?
Using a location header causes the browser to redirect to that script, and no data gets passed along with it (unless you add it to the query string). If an update was performed, a person could potentially stop their browser from loading the redirect by hitting stop fast enough. Also, chances are that script won't output anything meaningful to the user so they would be left with a blank page or data on their screen that they don't understand and would have to use the back button to return to your site.
If the update was run from a cron job or PHP CLI script, then the headers have no meaning anyway.
This should be done as a cURL
operation. The reason for this is your update scripts shouldn't be held responsible for handling browser operations like redirects; their job should just be to update whatever they need to update. By using cURL
you can move all of your code which handles whatever status codes are returned by the update script into something which presents that data to the user, instead of intermingling that with your update script. By using this approach, you can keep your update script clean and allow it to be called by multiple sources without worrying about misleading redirects.