Keep a Script Running When Client Disconnects

You may already know how to keep a PHP script running without timing out, however, if the client initiating the long-running script breaks a connection with the server, the PHP will become idle. LiteSpeed Web Server can automatically abort external application processes generating responses for that client to save server resouces. Some users, however, may have (long-running) processes that they wish to continue whether or not the client is still connected. The External Application Abort setting (found in LSWS Admin Console > Configuration > Server > General > General Settings) is meant to address such a need by setting it to No Abort.

External Application Abort has three options:

  • No Abort: Never abort external applications because of a broken connection.
  • Enable Abort for Requests from External IPs: Only processes started by requests from external IPs will be automatically aborted because of a broken connection. This is the default setting. It is a good setting if you have some internal long-running processes, like some cron jobs.
  • Enable Abort for All Requests: External application processes will be automatically aborted if the connection is broken, regardless of the source of the request.

If External Application Abort is unset, the default setting Enable Abort for All Requests will be applied. To enable no abort, you must explicitly set it to No Abort.

An application developer wants to use persistent MySQL connections with PHP. LSWS will automatically kill external applications after 30 seconds when the client breaks the connection. This causes MySQL to report the following in the error log:

[Warning] Aborted connection 197922 to db: 'database_table' user: 'root' host: 'localhost' (Got an error reading communication packets)

And this appears in the server's error log:

[21995] Cmd from child: [extappkill:22277:-3:0]
[22001] sendKillCmdToWatchdog: 'extappkill:22277:-3:0'.

It is a normal message and harmless for the end user. But for the application developer, killing an idle PHP process after 30 seconds will also kill the MySQL persistent connection, and thus the connection must be created again. This is a relatively expensive process. The application developer needs some queries running that must finish in order to maintain integrity, whether the PHP process is idle or not. For example, if something changes in DB 1, then DB 2 will have to be changed at the end of the PHP script. In this situation, setting External Application Abort to No Abort will solve the issue.

  • Admin
  • Last modified: 2019/06/27 15:35
  • by Lisa Clarke