文件上的PHP互斥/MySQL使用perl读取和执行文件中的语句 [英] PHP Mutual Exclusion on a File / MySQL reading and executing statements from a file using perl

查看:80
本文介绍了文件上的PHP互斥/MySQL使用perl读取和执行文件中的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想知道PHP如何/是否在文件读写方面具有某种互斥性.

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.

我对解决方案的想法

在将注册传递给支付服务之前,请先将sql语句处理并写入文件中,每组语句引用的注册均由某些令牌分隔.

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.

重述问题:

-问题是-在这种情况下,我需要在文件上互斥吗?如果是这样,我将如何实现?可以将其锁定为多种语言吗? (付款服务需要返回到cgi/perl脚本-尽管我可以包括实际处理的php脚本)

-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)

-我将如何运行并执行SQL语句(最好在perl中)?

-How would I run through and execute the SQL statements (preferably in perl)?

-我的解决方案看起来还不错吗?

-Does my solution even seem like a good one?

谢谢

特拉维斯

推荐答案

PHP和Perl均支持flock().

Both PHP and Perl support flock().

但是,更好的方法是使用数据库.您的数据库表可能具有processed列,用于指示付款是否已处理.当您将请求发送到支付服务时,请添加带有processed = 0的记录.返回注册后,用processed = 1更新表.

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.

这篇关于文件上的PHP互斥/MySQL使用perl读取和执行文件中的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆