开发者

a few questions regarding simultaneous mysql access from PHP and Django/Python

开发者 https://www.devze.com 2023-03-03 22:04 出处:网络
What I want to do(and have done) is to access the same MySQL db. and table from both a PHP script and a Django app. However i would like to know if the way I am doing this could cause开发者_运维技巧 e

What I want to do(and have done) is to access the same MySQL db. and table from both a PHP script and a Django app. However i would like to know if the way I am doing this could cause开发者_运维技巧 errors or issues. I hope you can help :)

The setup as of now:

The thing is I am setting up a 2 way SMS gateway thing. The user sends an sms message to the sms-gateway provider who then afterwards sends a POST request to an URL I specify.

mydomain.com/gateway/receive.php

This script inserts the data(defined by the gateway provider) message, sender, code into the MySQL db. and a table named gateway… as well as a variable called 'retrieved' which is a Boolean and =False at first. It then returns an XML response to the gateway provider so that they can be certain the sms message has been delivered(and notify the user via an sms message)

Every few minutes, my django app. looks through the same db. and table and looks for all sms entries with "retrieved=False". For each object a new object in the Django app is created with the same data (This object is then tied to the exact user, timestamped, formatted and so forth) and the original object from the gateway table is set to "retrieved=True" and then saved… (just in case… and for "log" purposes)

The reason I use PHP is because of the response time with my hosting service. PHP is a lot faster (directly behind an nginx server thingy) instead of the django app. which is on a custom build apache2 server. So in order for the sms part of the setup to work correctly I will have to use PHP for that part. Also I find that a simple PHP script is much less prone to downtime than a more complex apache2+Django setup.

So the question is… Could this cause any problems… Having a PHP and Django/Python script accessing the same mysql db. simultaneously? Is it at all the proper way of designing this sort of thing… My main concern is some sort of trouble with the PHP script inserting new stuff while the Django part reads/edits the older stuff(or the same stuff)

I hope this makes sense. And that you can help…? Could be a non-issue… I would just like to have a little certainty :)

Thanks.

Regards

pete


Use transactions, even in queries.


As long as your first process just inserts new data and the second processes/updates existing records you should be pretty safe. If not then you should look into using optimistic or pessimistic locking and/or using transactions.

0

精彩评论

暂无评论...
验证码 换一张
取 消