Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 49... Línea 49...
49
            debugging('Shutdown manager is already initialised!');
49
            debugging('Shutdown manager is already initialised!');
50
        }
50
        }
51
        self::$registered = true;
51
        self::$registered = true;
52
        register_shutdown_function(array('core_shutdown_manager', 'shutdown_handler'));
52
        register_shutdown_function(array('core_shutdown_manager', 'shutdown_handler'));
Línea 53... Línea 53...
53
 
53
 
54
        // Signal handlers should only be used when dealing with a CLI script.
54
        // Signal handlers are recommended for the best possible shutdown handling.
-
 
55
        // They require the 'pcntl' extension to be loaded and the following functions to be available:
55
        // In the case of PHP called in a web server the server is the owning process and should handle the signal chain
56
        // 'pcntl_async_signals'
56
        // properly itself.
57
        // 'pcntl_signal'
-
 
58
        // The 'pcntl' extension is optional and not available on Windows.
57
        // The 'pcntl' extension is optional and not available on Windows.
59
        if (extension_loaded('pcntl')) {
58
        if (CLI_SCRIPT && extension_loaded('pcntl') && function_exists('pcntl_async_signals')) {
60
            if (function_exists('pcntl_async_signals')) {
59
            // We capture and handle SIGINT (Ctrl+C) and SIGTERM (termination requested).
61
                // We capture and handle SIGINT (Ctrl+C) and SIGTERM (termination requested).
-
 
62
                pcntl_async_signals(true);
-
 
63
            }
60
            pcntl_async_signals(true);
64
            if (function_exists('pcntl_signal')) {
61
            pcntl_signal(SIGINT, ['core_shutdown_manager', 'signal_handler']);
65
                pcntl_signal(SIGINT, ['core_shutdown_manager', 'signal_handler']);
-
 
66
                pcntl_signal(SIGTERM, ['core_shutdown_manager', 'signal_handler']);
62
            pcntl_signal(SIGTERM, ['core_shutdown_manager', 'signal_handler']);
67
            }
63
        }
68
        }
Línea 64... Línea 69...
64
    }
69
    }
65
 
70
 
Línea 119... Línea 124...
119
     *
124
     *
120
     * @param callable $callback
125
     * @param callable $callback
121
     * @param array $params
126
     * @param array $params
122
     * @return void
127
     * @return void
123
     */
128
     */
124
    public static function register_signal_handler($callback, array $params = null): void {
129
    public static function register_signal_handler($callback, ?array $params = null): void {
125
        if (!is_callable($callback)) {
130
        if (!is_callable($callback)) {
126
            error_log('Invalid custom signal function detected ' . var_export($callback, true)); // phpcs:ignore
131
            error_log('Invalid custom signal function detected ' . var_export($callback, true)); // phpcs:ignore
127
        }
132
        }
128
        self::$signalcallbacks[] = [$callback, $params ?? []];
133
        self::$signalcallbacks[] = [$callback, $params ?? []];
129
    }
134
    }
Línea 133... Línea 138...
133
     *
138
     *
134
     * @param callable $callback
139
     * @param callable $callback
135
     * @param array $params
140
     * @param array $params
136
     * @return void
141
     * @return void
137
     */
142
     */
138
    public static function register_function($callback, array $params = null): void {
143
    public static function register_function($callback, ?array $params = null): void {
139
        if (!is_callable($callback)) {
144
        if (!is_callable($callback)) {
140
            error_log('Invalid custom shutdown function detected '.var_export($callback, true)); // phpcs:ignore
145
            error_log('Invalid custom shutdown function detected '.var_export($callback, true)); // phpcs:ignore
141
        }
146
        }
142
        self::$callbacks[] = [$callback, $params ? array_values($params) : []];
147
        self::$callbacks[] = [$callback, $params ? array_values($params) : []];
143
    }
148
    }