0

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

  • what a world we live in. we downvote and refuse to answer when somebody fails to say "thank you". isn't the purpose of stackoverflow to help people? – christopher Oct 02 '12 at 05:38
  • @christopher here people are helped only if they try something from their side first, if answer is available just by searching on the internet, or if the question is too vague, it's ignored, as it helps a programmer to learn things himself, easily giving help to everyone won;''t actually help the programmer to understand, he will just copy paste the code ... – Mr. Alien Oct 02 '12 at 05:44

1 Answers1

0

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 processed column that indicates whether the payment has been processed. When you send the request to the payment service add a record with processed = 0. When the registration is returned, update the table with processed = 1.

Barmar
  • 741,623
  • 53
  • 500
  • 612