Accessing MySQL from PHP and another process at the same time
I'm writing a program that runs (24/7) on a Linux server and adds entries to a MySQL database. The contents of the database are presented on a web interface with PHP and the use开发者_开发知识库r should be able to delete entries using the web interface. Is it possible to access the database from multiple processes at the same time?
Yes, databases are designed for this purpose quite well. You'll want to keep a few things in mind in your designs:
- Concurrency and race conditions on database writes.
- Performance.
- Separate database permissions for separate applications.
Unless you're doing something like accessing the DB using a singleton, the max number of simultaneous mysql connections php will use is limited in your php.ini. I believe it defaults to 100.
Yes multiple users can access the database at the same time. You should however take care that the data is consistent. If you create/edit entry with many small sql statements and in the meantime someone useses the web interface this may lead to some errors. If you have a simple db this should not be a problem, else you should consider using transactions.
http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html
Yes and there will not be any problems while trying to delete records in the presence of that automated program which runs 24/7 if you are using the InnoDb engine. This is because transactions happen one at a time, one starts after another has finished and the database is consistent everytime.
This answer How to implement the ACID model for a database has many relevant points.
Read about the ACID Properties of a database. A Mysql database with InnoDb engine will take care of all these things for you and you need not worry about that.
精彩评论