This is an old revision of the document!


How to keep a script running even the client disconnected?

You may already know how to keep a PHP script running without timeout, however, if the client initiating the long run script breaks a connection with the server, the long run 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 running whether or not the client is still connected. External Application Abort setting(LSWS Admin Console→ Configuration→ Server→ General → General Settings → External Application Abort) is just for such need and you can set it to No Abort.

There are three options for this:

  • 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 this setting unset, the default setting Enable Abort for All Requests will be applied. To enable no abort, you should set it to No Abort.

The following is the example use case.

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, which causes MySQL to report in the error log:

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

In server's error log:

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

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

  • Admin
  • Last modified: 2019/06/27 14:50
  • by Jackson Zhang