user1105787
user1105787

Reputation:

How do I view the status of my msql query?

I recently executed a mysql query via chrome and closed it out. How exactly does a browser stop a PHP script using the stop button? I thought PHP was a server-side language and could not be controlled through a client.

*UPDATE*I'm now aware of SHOW PROCESSLIST, but this only shows you which threads are running.Is there a SQL command I can use to view a executed query with great detail?

Upvotes: 0

Views: 221

Answers (6)

Colin M
Colin M

Reputation: 13348

Come on guys, this is PHP 101. Quoted from the manual:

You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects.

Execution will stop at the next tickable event after the connection flag is set to ABORTED - which will be detected when PHP attempts to flush output to the client

The current MySQL query will finish executing (as the next event that PHP has control over doesn't occur until after the query has completed), but your script would not make it past that, unless you explicitly set ignore_user_abort. It's always important to account for this when writing code.

There are two ways around this

  1. Set ignore_user_abort to true for the invocation of your script
  2. Do not print anything back to the client until after all of your processing is complete - since a connection closed status won't be detected until output is flushed

Upvotes: 0

CodeMonkey
CodeMonkey

Reputation: 3331

The Answer is it depends, as others mentioned you can check what is running on the mysql server by using the show processlist;

If it is a single query that takes a long time, the it will most likely carry on running after the browser has closed. PHP will have sent the request to the Database and will in effect be sat waiting for it to complete, in turn the browser will be waiting for the webserver to finish building the page/resource that is on that url

so the request is: browser <-> web server (<-> php ) <-> mysql in an ideal world if the user cancels the request everything would tidy itself up nicely, but that in my experience sadly is not the case, if one of the chain decides not to wait, the process that it is waiting for doesn't necessarily know until it tries to send the response back and fails

Upvotes: 0

SomeShinyObject
SomeShinyObject

Reputation: 7821

No, you don't need to keep it open. If you exit a running car, does the car turn off? No.

Sorry, that came off a little snotty, but it wasn't intended too.

The browser, in your case Chrome, is not actually running the actual code. The server is. Thus, once the instruction is executed, closing the browser no longer matters as the request has been given to the server.

Upvotes: 1

phpisuber01
phpisuber01

Reputation: 7715

The script will continue to execute regardless of browser closure. You can free up your browser by sending the response and allowing the php process to continue on.

ignore_user_abort(true);
$response = "Processing!"; 
header("Connection: close");
header("Content-Length: " . mb_strlen($response));
echo $response;
flush();

// Insert your lengthy query here

Upvotes: 0

x4rf41
x4rf41

Reputation: 5337

two functions are essential for executing time consuming php scripts. it has nothing to do with the browser (as other users already pointed out)

lookup ignore_user_abort and set_time_limit

Upvotes: 0

feeela
feeela

Reputation: 29932

A client (Chrome) has nothing to do with the execution of scripts (PHP) on the server, which in turn have no control over database processes (MySQL query).

Look at your servers process list to see what's going on in general (Apache processes).

Or even better: use SHOW PROCESSLIST; on the MySQL console to find the long running query. You may quit it by using KILL ###ID_OF_QUERY###;.

Upvotes: 1

Related Questions