PHP: Skip MySql Query if it takes more than a second

I have a php page that needs to be written to the database sometimes at the beginning of the script.

The page is unavailable during a scheduled mysqldump backup because it is trying to write to a locked table.

During the lock, MySql queues these sql updates, and after the backup is completed, they are performed as desired. However, my php page will not be displayed until the backup is complete.

However, since updates do not return anything to the script, I would like them to not hang my script during blocking; I hope I can tell php to just send the sql update to mysql and not worry about confirming that the update is complete.

I want php to send the request to mysql and then just go to the next line of php if the update does not complete in one second.

I am running php on a Windows server, so I understand that some type of streaming is not an option.

If there is a way to set a timeout on this request (in particular), this may be ideal, but I do not want to refuse to upgrade sql at all if it expires. I still want MySQL to process it after the lock has disappeared.

What would you recommend (given that removing sql updates is not an option at all)?

+5
source share
3 answers

, , , , , SQL, :

function isLocked($databaseName,$tableName)
    {
        $sql = "show open tables from `".$databaseName."` where `table`=`".tableName."` and In_use > 0;";
        $result = @mysql_query($sql);
        if (mysql_num_rows($result) != 0 )
        {
            return true;
        }
        else
        {
            return false;
        }
    }

(: , )

, , sql , .

+3

, PDO, -, , , .

PDO PDO:: ATTR_TIMEOUT.

+3

I think this is the only way to do this, to split you into a script into pieces and use ajax calls, you can send a big update and continue with the rest of the script, which is independent of this process, if all the script depends on the update result, the only way - make a nice download ...

+1
source

All Articles