Advanced configuration in PHP


Configuring the PHP Extension

Sqreen settings can be optionally adjusted according to your needs. This section lists the possible configuration options you have with Sqreen PHP agent.

Default Port Bindings

The daemon and the PHP extension use TCP to communicate. The daemon listens on port 7773 by default (binding on 0.0.0.0).

The PHP extension will try to connect to 127.0.0.1:7773 by default.

Configuration sources

The Sqreen PHP extension read its configuration from the PHP configuration (.ini files). This file is typically located in /etc/php/7.0/mods-available/sqreen.ini.

Configuration variables

The Sqreen PHP extension can be configured using the environment or a JSON file. Here are the settings that can be changed:

sqreen.ini variable name Role Default value
sqreen.token The Sqreen token. This identifies the agent to Sqreen backend servers empty
sqreen.log_location Specify a custom file to write Sqreen logs /tmp/
sqreen.log_level Sqreen logging level critical
sqreen.socket_path The address of the Sqreen daemon. 127.0.0.1:7773

Multiple sites

Serving multiple sites from the same PHP engine is supported by Sqreen. Many tokens can be recorded in different .ini files.

SELinux

If you use SELinux you may need to authorize the extension to comunicate with the daemon.

For instance for httpd on centos just do this command (from the package policycoreutils-python)

semanage port -a -t http_port_t -p tcp 7773

Configuring the PHP daemon

Sqreen settings can be optionally adjusted according to your needs. This section lists the possible configuration options you have with Sqreen daemon for the PHP extension. The daemon can support any number of PHP clients.

Configuration sources

The Sqreen Agent read its configuration from different places: * The environment * A Python .ini file * The command line interface.

The .ini file can be located in: * Your application top level directory: sqreen.ini * In a custom place set by the SQREEN_CONFIG_FILE environment variable:

export SQREEN_CONFIG_FILE=/custom/path/sqreen.ini 

Configuration variables

The Sqreen agent can be configured using the environment or a JSON file. Here are the settings that can be changed:

Env variable name Role .ini key name CLI flag Default value
SQREEN_CONFIG_FILE Custom location for the .ini based configuration file --config Empty
SQREEN_LOG_LOCATION Specify a custom file to write Sqreen logs log_location --log-location Empty
SQREEN_LOG_LEVEL Sqreen logging level. One of DEBUG or CRITICAL. log_level --log-level CRITICAL
SQREEN_BACKGROUND The daemon to start in background --background False
SQREEN_LISTEN The host and port the daemon will listen on, with the form host:port listen --listen 0.0.0.0:7773
SQREEN_PROXY_URL The url of a proxy use to connect to the Backend proxy_url --proxy_url Empty

Usage on a high performance application

The Sqreen agent will be listening to each PHP process using one TCP connection. The ulimit of your system should allow this process to use such a count of TCP sockets.

The following file need to go in the /etc/security/limits.conf file:

# Allow Sqreen to receive enough connections
sqreen hard nofile 1000