Reputation: 3158
If I use a large function that will update data on MySQL and then execute header("Location: somepage")
, will PHP wait before all those update queries are done and then redirect or do I have to account for that?
Upvotes: 0
Views: 131
Reputation: 1803
From the php documentation
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
Then... if it return the success or failure, it must wait until the update has finished.
Upvotes: 1
Reputation: 490183
PHP code is executed in a predicable sequential pattern, top down.
If you run some database queries the database server will handle them, PHP's thread doesn't handle the writing itself (just passes the query over).
MyISAM tables are locked on write and and I'm pretty sure the UPDATE
queries are atomic (meaning they either all do or don't happen - they don't leave things half finished).
Also, slightly tangential, don't forget to exit
after sending the Location
header. User agents are free to ignore the Location
header.
Upvotes: 4
Reputation: 136
Yes, PHP will sequentially execute each command and will only reach the redirect statement once the update queries have reported success.
Upvotes: 4