Skip to content

PHP LSAPI (lsphp)

LSAPI (LiteSpeed Server Application Programming Interface) is LiteSpeed’s proprietary protocol for communicating with PHP. Unlike FastCGI, which serializes data into a binary stream over a socket, LSAPI uses shared memory for data transfer, reducing system call overhead and memory copies.

AspectLSAPI (lsphp)FastCGI (PHP-FPM)
ProtocolShared memory + socketSocket only
Process managementOLS manages workersPHP-FPM manages workers
PerformanceFaster (fewer copies)Slightly slower
MemoryLower per-request overheadHigher per-request overhead
PHP opcode cacheShared across childrenShared within FPM pool
ConfigurationOLS extprocessorphp-fpm.conf + pool.d
suEXECBuilt-in supportRequires pool-per-user

For most use cases, LSAPI is the recommended choice. Use PHP-FPM only when you need independent process management or compatibility with other web servers.

  1. OLS starts the lsphp binary as a parent process.
  2. The parent process forks PHP_LSAPI_CHILDREN worker processes.
  3. Each worker handles one request at a time over a Unix domain socket.
  4. After LSAPI_MAX_REQS requests, a worker exits and the parent forks a replacement.
  5. Idle workers beyond PHP_LSAPI_MAX_IDLE seconds are terminated to reclaim memory.

The lsphp external application is defined in httpd_config.conf:

extprocessor lsphp {
type lsapi
address uds://tmp/lshttpd/lsphp.sock
maxConns 10
env PHP_LSAPI_CHILDREN=10
env LSAPI_MAX_REQS=5000
env PHP_LSAPI_MAX_IDLE=300
initTimeout 60
retryTimeout 0
persistConn 1
respBuffer 0
autoStart 1
path /usr/local/lsws/fcgi-bin/lsphp
backlog 100
instances 1
priority 0
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 1400
procHardLimit 1500
}
ParameterDescription
typeMust be lsapi for lsphp
addressUnix domain socket path. uds:// prefix is required.
maxConnsMaximum concurrent connections. Should match PHP_LSAPI_CHILDREN.
autoStartSet to 1 to let OLS start lsphp automatically.
pathAbsolute path to the lsphp binary.
instancesNumber of lsphp parent processes. Usually 1.
memSoftLimitPer-process memory soft limit.
memHardLimitPer-process memory hard limit.

Map PHP file extensions to the lsphp external application:

scripthandler {
add lsapi:lsphp php
}

This tells OLS to route all .php requests to the lsphp extprocessor.

OLS supports running lsphp under different user accounts per virtual host. In the virtual host configuration:

virtualhost example {
...
extprocessor lsphp {
type lsapi
address uds://tmp/lshttpd/example_lsphp.sock
maxConns 5
env PHP_LSAPI_CHILDREN=5
autoStart 1
path /usr/local/lsws/fcgi-bin/lsphp
instances 1
}
scripthandler {
add lsapi:lsphp php
}
setUIDMode 2
}

Setting setUIDMode to 2 (suEXEC) causes OLS to start the lsphp process as the owner of the document root directory.

When OLS starts, it creates the parent lsphp process, which then forks children on demand. The first request to each child incurs a cold-start penalty (loading PHP, extensions, opcode cache). To pre-warm:

Terminal window
# Set children to start immediately
env PHP_LSAPI_CHILDREN=10

When you run systemctl restart lsws, OLS sends a graceful shutdown signal. Active PHP requests finish before workers exit. New workers are forked by the new parent process.

To restart only lsphp without restarting OLS:

Terminal window
killall -USR1 lsphp

This causes the parent lsphp to gracefully restart all children.

lsphp not starting:

  • Check that the binary exists at the configured path
  • Verify the binary has execute permissions
  • Check /usr/local/lsws/logs/stderr.log for PHP startup errors

502 Bad Gateway:

  • The lsphp process crashed or is not running
  • Check maxConns matches PHP_LSAPI_CHILDREN
  • Review /usr/local/lsws/logs/error.log

High memory usage:

  • Reduce PHP_LSAPI_CHILDREN
  • Lower LSAPI_MAX_REQS to recycle workers more frequently
  • Check for PHP memory leaks in application code