PHPackages                             laynefyc/php-monitor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. laynefyc/php-monitor

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

laynefyc/php-monitor
====================

A free, flexible, powerful tool that helps you monitor PHP Service.

v1.0.1(6y ago)23552734[16 issues](https://github.com/laynefyc/php-monitor/issues)MITPHPPHP ^5.6 || ^7.0CI failing

Since Jan 11Pushed 5y ago2 watchersCompare

[ Source](https://github.com/laynefyc/php-monitor)[ Packagist](https://packagist.org/packages/laynefyc/php-monitor)[ RSS](/packages/laynefyc-php-monitor/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (3)Dependencies (4)Versions (7)Used By (0)

php-monitor
===========

[](#php-monitor)

A free, flexible, powerful tool that helps you monitor PHP Service and profiling PHP code.

[![Latest Stable Version](https://camo.githubusercontent.com/b0830726f39c7715705c2887dfcd8ee9a1ec3e2c63676b52780ff2f730a7ccd7/68747470733a2f2f706f7365722e707567782e6f72672f6c61796e656679632f7068702d6d6f6e69746f722f762f737461626c652e706e67)](https://packagist.org/packages/laynefyc/php-monitor)[![Total Downloads](https://camo.githubusercontent.com/b6796a75e0c43e60c116fa40b341178771b66d0b3085120f89846e8a2a82f4ad/68747470733a2f2f706f7365722e707567782e6f72672f6c61796e656679632f7068702d6d6f6e69746f722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/laynefyc/php-monitor)[![Build Status](https://camo.githubusercontent.com/c5445340e2a9178e53441054b7f1d309b191e7e95c9d8182407e9a630250824f/68747470733a2f2f7472617669732d63692e6f72672f6c61796e656679632f7068702d6d6f6e69746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/laynefyc/php-monitor)

[![home](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/home.png)](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/home.png)

[![](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/infomation.png)](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/infomation.png)

[![flame](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/flame.png)](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/flame.png)

[![url](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/url.png)](https://raw.githubusercontent.com/laynefyc/php-monitor/screenshot/screenshot/url.png)

English | [简体中文](./README-zh_CN.md)

✨ Features
----------

[](#-features)

- 🌈 Get detailed PHP runtime data.
- 🌍 Monitor production environment time consuming requests.
- 🛡 Displays the memory and CPU consumption of the underlying function.
- 🎨 Use various kinds of visual graphics to display data.

⚙️ System requirements
----------------------

[](#️-system-requirements)

- uprofiler,xhprof,tideways php extension(default tideways).
- composer
- PHP 5.6+

Install tideways extension
==========================

[](#install-tideways-extension)

PHP 5.6(download tideways v4.1.5) PHP 7.0+(download tideways v4.1.7)

```
wget --no-check-certificate https://github.com/tideways/php-xhprof-extension/archive/v4.1.7.tar.gz  && tar zxvf v4.1.7.tar.gz && cd php-xhprof-extension-4.1.7 && phpize && ./configure && make && sudo make install
```

Add configuration data on `php.ini`.You should see something like:

```
extension=tideways.so
```

Once installed, you can use the following command to check:

```
> php --ri tideways
tideways
tideways => 4.1.7
```

Install php-monitor
===================

[](#install-php-monitor)

```
composer create-project --prefer-dist --ignore-platform-reqs laynefyc/php-monitor php-monitor && cd php-monitor/public && php -S 127.0.0.1:8066
```

Visit  and input account and password(php/php).

Detailed installation tutorial
------------------------------

[](#detailed-installation-tutorial)

1. Download &amp; Update Projects

    ```
    composer create-project --prefer-dist --ignore-platform-reqs laynefyc/php-monitor php-monitor
    ```

    or

    ```
    git clone https://github.com/laynefyc/php-monitor.git
    cd php-monitor
    composer update --ignore-platform-reqs
    ```
2. The project can set data storage mode and supports MySQL, MongoDB, SQLite. Set in configuration file `src/config/config.php`,The information is as follows:

    ```
    // 'save' => [
    //     'driver'    => 'mysql',
    //     'host'      => '127.0.0.1:3306',
    //     'database'  => 'php_monitor',
    //     'username'  => '',
    //     'password'  => 'abcd1234',
    //     'charset'   => 'utf8mb4'
    // ],
    // 'save' => [
    //     'driver'    => 'mongodb',
    //     'host'      => '127.0.0.1:27017',
    //     'database'  => 'php_monitor',
    //     'username'  => '',
    //     'password'  => ''
    // ],
    'save' => [
        'driver'    => 'sqlite',
        'database'  =>  dirname(__DIR__).'/db/php_monitor.sqlite3'
    ],
    ```

    SQLite is used by default in this project，if you use other databases, please uncomment them.

    If you want to use MySQL to run the following table creation statement (table name cannot be modified):

    ```
    CREATE TABLE `php_monitor` (
    	`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Auto-increment number ',
    	`url` text CHARACTER SET utf8 COMMENT 'Request URL',
    	`server_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT 'Service name',
    	`get` text COMMENT 'GET parameter',
    	`pmu` int(11) unsigned DEFAULT NULL COMMENT 'Memory spike',
    	`wt` int(11) unsigned DEFAULT NULL COMMENT 'Total time spent in microseconds',
    	`cpu` int(11) unsigned DEFAULT NULL COMMENT 'Total CPU cycle time',
    	`ct` int(3) NOT NULL COMMENT 'Total calls',
    	`mu` int(11) unsigned DEFAULT NULL COMMENT 'Current memory consumption',
    	`request_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Request time accurate to seconds',
    	`request_time_micro` int(10) unsigned DEFAULT '0' COMMENT 'Request time accurate to microseconds',
    	`profile` longblob NOT NULL COMMENT 'performance data,
    	`server` longblob COMMENT 'SERVER parameter',
    	`type` varchar(16) DEFAULT NULL COMMENT 'Request time includes GET，POST',
    	`ip` varchar(16) DEFAULT NULL COMMENT 'IP address',
    	PRIMARY KEY (`id`),
    	KEY `idx_url` (`url`),
    	KEY `idx_ip` (`ip`)
    ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
    ```

    Mongodb database will build its own tables, but it needs to add indexes by yourself.The adding way as follows：

    ```
    show dbs
    use php_monitor //Please select your own database
    db.php_monitor.createIndex({"url":1})
    db.php_monitor.createIndex({"ip":1})
    ```

    The table name for all data storage methods must be `php_monitor` and does not support modification.
3. The operation of monitoring platform

    It can directly pass the following command during testing：

    ```
    cd php-monitor/public
    php -S 127.0.0.1:8066

    ```

    After running successfully ,It can be accessed directly .

    Non-test environment please use Nginx.The configuration is as follows：

    ```
    server {
        listen       8066;
        server_name  localhost;
        root /home/www/cai/php-monitor/public;
        index  index.php index.html;
        location / {
            root /home/www/cai/php-monitor/public;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
        }
    }
    ```
4. Login background

    Login account password can be modified directly in the configuration file，`src/config/config.php`。

    ```
    'user' => [
        //login account and password
        ['account'=>'php','password'=>'php'],
        ['account'=>'admin','password'=>'abcd']
    ]

    ```

    Please change the account number and password in time after release. If you require a higher level of security, please extend the method of Login Controller.php file.
5. Introduce monitoring into the project.

    The project is monitored in a non-invasive way, without any interference to the service in operation.

    There are two ways to add monitoring to a project. One is to modify the nginx configuration：

    For example, to monitor the running service [www.site.com](http://www.site.com), you only need to add a line of configuration information in the nginx configuration file

    ```
    fastcgi_param PHP_VALUE "auto_prepend_file={php-monitor-path}/src/autoPrepend.php";
    ```

    The effect of adding configuration is as follows (other content is just for demonstration, not the same nginx configuration)：

    ```
    server {
      listen 80;
      server_name www.site.com;
      root your/webroot/;
      location ~ \.php$ {
          fastcgi_pass   127.0.0.1:9000;
          include        fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
          fastcgi_param PHP_VALUE "auto_prepend_file={php-monitor-path}/src/autoPrepend.php";
      }
    }
    ```

    This way is to use the `auto_prepend_file` interface provided by PHP，interfaceing .You need to restart nginx after adding configuration.

    The second way is to import the entry file that needs to monitor the project directly , usually add it in `public/index.php`：

    ```
    require '/home/www/cai/php-monitor/src/autoPrepend.php';
    ```

    The effect after adding configuration is as follows (except the core code, the other code is for demonstration):

    ```
