PHP Integration
OpenLiteSpeed is especially well known for efficient PHP delivery. The core of that integration is LSAPI and the lsphp runtime.
LSAPI (LiteSpeed SAPI)
PHP LSAPI Overview
LSAPI is LiteSpeed's interface for running PHP processes efficiently with low overhead and strong reuse of worker processes.
Process Management
OpenLiteSpeed can spawn and manage PHP workers through an external application definition. You control limits such as max connections, environment variables, process count, and idle timeout.
Performance Benefits
- Faster reuse than classic CGI patterns
- Lower process creation overhead
- Good fit for high-concurrency PHP applications
- Tight integration with OpenLiteSpeed process controls
External Applications
lsphp Configuration
Define an external app in WebAdmin or config files that points to a specific lsphp binary, such as /usr/local/lsws/lsphp84/bin/lsphp.
Socket Configuration
Unix domain sockets are commonly used because they are efficient for same-host communication.
Example socket path:
uds://tmp/lshttpd/example.sock
Command Setup
The command usually points to the lsphp binary and may include environment variables for PHP INI selection or app-specific settings.
Script Handlers
PHP Handler Mapping
Map the .php suffix to the external app so PHP files are executed by the correct lsphp instance.
Multiple PHP Versions
You can define more than one external app and assign different script handlers per virtual host. This is useful when one application needs PHP 8.1 and another needs PHP 8.3 or 8.4.
PHP Optimization
OPcache
Enable OPcache in production so compiled PHP bytecode is reused across requests.
Memory Limits
Set PHP memory limits based on application behavior, not guesswork. A CMS with plugins may need more than a small custom app.
Process Limits
Right-size PHP workers to available RAM. Too few workers increase queueing. Too many workers cause swap pressure and worse performance.
Example Planning Model
| Item | Guideline |
|---|---|
| Socket | Prefer Unix socket for local PHP |
| OPcache | Enable in production |
| Worker count | Size from RAM and peak concurrency |
| PHP versioning | Separate handlers when apps differ |
| Memory limit | Tune from real application usage |
Operational Advice
- Keep
lsphpversions aligned with application support policies - Restart or reload PHP workers after major INI changes
- Avoid globally increasing limits without measuring impact
- Document which virtual hosts use which PHP binary and socket