So I was wondering how / if PHP has some sort of mutual exclusion on file reading and writing.
Here’s how I plan on using it:
The site I’m working with utilizes a payment service that requires leaving the server, making it difficult to deal with form submissions, such that the form does not get submitted into the database until after returning from the payment service. Information CAN be passed through the payment service and regurgitated on the other end. However, there is minimum information that can be passed.
My idea of a solution:
Before a registration is passed to the payment service, process and write the sql statements in a file, with each group of statements referring to a registration separated by some token.
On returning find the entry based on the information you sent through the payment service, execute the statements and remove the registration block from the file.
Rephrasing the question:
-So the question is – in this scenario would I need mutual exclusion on the file, and if so how would I achieve it? Could this be locked from multiple languages? (The payment service requires returning to a cgi / perl script – although I could include a php script that actually processes)
-How would I run through and execute the SQL statements (preferably in perl)?
-Does my solution even seem like a good one?
Thanks,
Travis
Both PHP and Perl support
flock().However, a better way to do it would be to use the database. Your DB table could have a
processedcolumn that indicates whether the payment has been processed. When you send the request to the payment service add a record withprocessed = 0. When the registration is returned, update the table withprocessed = 1.