PHP Mutual Exclusion on a File / MySQL reading and executing statements from a file using perl

隐身守侯 提交于 2019-12-13 02:42:24

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/12685029/php-mutual-exclusion-on-a-file-mysql-reading-and-executing-statements-from-a-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!