<commit_before><?php


namespace ZPHP\Socket\Callback;

use ZPHP\Socket\ICallback;
use ZPHP\Core\Config as ZConfig;
use ZPHP\Protocol;


abstract class Swoole implements ICallback
{

    protected $protocol;

    protected $serv;

    /**
     * @throws \Exception
     * @desc 服务启动，设置进程名及写主进程id
     */
    public function onStart()
    {
        /**
         * @var $server \swoole_server
         */
        $server = func_get_args()[0];
        $ip = ZConfig::getField('socket', 'host');
        $port = ZConfig::getField('socket', 'port');
        swoole_set_process_name(ZConfig::get('project_name') .
            ' server running ' .
            ZConfig::getField('socket', 'server_type', 'tcp') . '://' . $ip . ':' . $port
            . " time:" . date('Y-m-d H:i:s') . "  master:" . $server->master_pid);
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            file_put_contents($pidPath . DS . ZConfig::get('project_name') . '_master.pid', $server->master_pid);
        }
        if ('Ant' == ZConfig::get('project', 'server_type')) {
            $callback = ZConfig::getField('soa', 'register_callback', 'socket\Handler\Soa::register');
        } else {
            $callback = ZConfig::getField('soa', 'register_callback');
        }
        if (!empty($callback)) {
            call_user_func($callback, $server);
        }
    }

    /**
     * @throws \Exception
     */
    public function onShutDown()
    {
        $server = func_get_args()[0];
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            $filename = $pidPath . DS . ZConfig::get('project_name') . '_master.pid';
            if (is_file($filename)) {
                unlink($filename);
            }
            $filename = $pidPath . DS . ZConfig::get('project_name') . '_manager.pid';
            if (is_file($filename)) {
                unlink($filename);
            }
        }
        if ('Ant' == ZConfig::get('project', 'server_type')) {
            $callback = ZConfig::getField('soa', 'drop_callback', 'socket\Handler\Soa::drop');
        } else {
            $callback = ZConfig::getField('soa', 'drop_callback');
        }
        if (!empty($callback)) {
            call_user_func($callback, $server);
        }
    }

    /**
     * @param $server
     * @throws \Exception
     * @desc 服务启动，设置进程名
     */
    public function onManagerStart($server)
    {
        swoole_set_process_name(ZConfig::get('project_name') .
            ' server manager:' . $server->manager_pid);
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            file_put_contents($pidPath . DS . ZConfig::get('project_name') . '_manager.pid', $server->manager_pid);
        }
    }

    /**
     * @param $server
     * @throws \Exception
     * @desc 服务关闭，删除进程id文件
     */
    public function onManagerStop($server)
    {
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            $filename = $pidPath . DS . ZConfig::get('project_name') . '_manager.pid';
            if (is_file($filename)) {
                unlink($filename);
            }
        }
    }

    public function onWorkerStart($server, $workerId)
    {
        $workNum = ZConfig::getField('socket', 'worker_num');
        if ($workerId >= $workNum) {
            swoole_set_process_name(ZConfig::get('project_name') . " server tasker  num: " . ($server->worker_id - $workNum) . " pid " . $server->worker_pid);<commit_msg>server map add ant<commit_after><?php


namespace ZPHP\Socket\Callback;

use ZPHP\Socket\ICallback;
use ZPHP\Core\Config as ZConfig;
use ZPHP\Protocol;


abstract class Swoole implements ICallback
{

    protected $protocol;

    protected $serv;

    /**
     * @throws \Exception
     * @desc 服务启动，设置进程名及写主进程id
     */
    public function onStart()
    {
        /**
         * @var $server \swoole_server
         */
        $server = func_get_args()[0];
        $ip = ZConfig::getField('socket', 'host');
        $port = ZConfig::getField('socket', 'port');
        swoole_set_process_name(ZConfig::get('project_name') .
            ZConfig::get('server_mode') . ' server running ' .
            ZConfig::getField('socket', 'server_type', 'tcp') . '://' . $ip . ':' . $port
            . " time:" . date('Y-m-d H:i:s') . "  master:" . $server->master_pid);
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            file_put_contents($pidPath . DS . ZConfig::get('project_name') . '_master.pid', $server->master_pid);
        }
        if ('Ant' == ZConfig::get('server_mode')) {
            $callback = ZConfig::getField('soa', 'register_callback', 'socket\Handler\Soa::register');
        } else {
            $callback = ZConfig::getField('soa', 'register_callback');
        }
        if (!empty($callback)) {
            call_user_func($callback, $server);
        }
    }

    /**
     * @throws \Exception
     */
    public function onShutDown()
    {
        $server = func_get_args()[0];
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            $filename = $pidPath . DS . ZConfig::get('project_name') . '_master.pid';
            if (is_file($filename)) {
                unlink($filename);
            }
            $filename = $pidPath . DS . ZConfig::get('project_name') . '_manager.pid';
            if (is_file($filename)) {
                unlink($filename);
            }
        }
        if ('Ant' == ZConfig::get('server_mode')) {
            $callback = ZConfig::getField('soa', 'drop_callback', 'socket\Handler\Soa::drop');
        } else {
            $callback = ZConfig::getField('soa', 'drop_callback');
        }
        if (!empty($callback)) {
            call_user_func($callback, $server);
        }
    }

    /**
     * @param $server
     * @throws \Exception
     * @desc 服务启动，设置进程名
     */
    public function onManagerStart($server)
    {
        swoole_set_process_name(ZConfig::get('project_name') .
            ZConfig::get('server_mode') . ' server manager:' . $server->manager_pid);
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            file_put_contents($pidPath . DS . ZConfig::get('project_name') . '_manager.pid', $server->manager_pid);
        }
    }

    /**
     * @param $server
     * @throws \Exception
     * @desc 服务关闭，删除进程id文件
     */
    public function onManagerStop($server)
    {
        $pidPath = ZConfig::getField('project', 'pid_path');
        if (!empty($pidPath)) {
            $filename = $pidPath . DS . ZConfig::get('project_name') . '_manager.pid';
            if (is_file($filename)) {
                unlink($filename);
            }
        }
    }

    public function onWorkerStart($server, $workerId)
    {
        $workNum = ZConfig::getField('socket', 'worker_num');
        if ($workerId >= $workNum) {
            swoole_set_process_name(ZConfig::get('project_name') . " server tasker  num: " . ($server->worker_id - $workNum) . " pid " . $server->worker_pid);
{'fraction_non_alphanumeric': 0.16697016388849978, 'fraction_numerical': 0.0005603025633842274, 'mean_word_length': 2.1989247311827955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5977964', 'n_tokens_mistral': 2246, 'n_tokens_neox': 2235, 'n_words': 370}