If I have a php script which calls INSERT, UPDATE, DELETE, etc on a MySQL connection, and that script gets called at uncontrolled times by a POST operation, is it always "safe" (ie, will not result in corrupt tables or collisions during requests)?
For example, if 500 requests come during a 1-second period.
If so, how does php/mysql achieve this?
If not, what does one need to do to guarantee "serial" access or safe simultaneous access?
It is not thread-safe, so call it before threads are created, or protect the call with a mutex. Arrange for mysql_thread_init() to be called early in the thread handler before calling any MySQL function. (If you call mysql_init() , it calls mysql_thread_init() for you.)
Thread-safety is recommended when the web server run multiple threads of execution simultaneously for different requests. In Thread Safety binary can work in a multi-threaded web server context. Thread Safety works by creating a local storage copy in each thread so that the data will not collide with another thread.
With PHP, you can connect to and manipulate databases. MySQL is the most popular database system used with PHP.
Open a phpinfo() and search for the line Thread safety. For a thread-safe build you should find enable. As specified in the comments by Muhammad Gelbana you can also use: On Windows : php -i|findstr "Thread"
MySQL uses locking (table-level for MyISAM or row-level for InnoDB), which does not allow 2 processes (2 calls to the script) to modify the same row. So the table won't crash*, but it's possible that MySQL can't handle the number of request in reasanoble time and the requests will wait. You should always optimize your queries to be as fast as possible.
*MyISAM could crash on insert/update intensive applications, but it has automatic recovery. However keep in mind that in such application, InnoDB has far better performance
is it always "safe" (ie, will not result in corrupt tables or collisions during requests)?
yes
If so, how does php/mysql achieve this?
table/row locks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With