1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- require_once __DIR__.'/../../vendor/workerman/workerman/Worker.php';
- use Workerman\Worker;
- use Workerman\Protocols\Http\Request;
- use Workerman\Protocols\Http\Response;
- use Workerman\Connection\TcpConnection;
- require_once __DIR__ . '/../../vendor/autoload.php';
- $web = new Worker("http://0.0.0.0:55151");
- $web->count = 2;
- define('WEBROOT', __DIR__ . DIRECTORY_SEPARATOR . 'Web');
- $web->onMessage = function (TcpConnection $connection, Request $request) {
- $_GET = $request->get();
- $path = $request->path();
- if ($path === '/') {
- $connection->send(exec_php_file(WEBROOT.'/index.php'));
- return;
- }
- $file = realpath(WEBROOT. $path);
- if (false === $file) {
- $connection->send(new Response(404, array(), '<h3>404 Not Found</h3>'));
- return;
- }
-
- if (strpos($file, WEBROOT) !== 0) {
- $connection->send(new Response(400));
- return;
- }
- if (\pathinfo($file, PATHINFO_EXTENSION) === 'php') {
- $connection->send(exec_php_file($file));
- return;
- }
- $if_modified_since = $request->header('if-modified-since');
- if (!empty($if_modified_since)) {
-
- $info = \stat($file);
- $modified_time = $info ? \date('D, d M Y H:i:s', $info['mtime']) . ' ' . \date_default_timezone_get() : '';
- if ($modified_time === $if_modified_since) {
- $connection->send(new Response(304));
- return;
- }
- }
- $connection->send((new Response())->withFile($file));
- };
- function exec_php_file($file) {
- \ob_start();
-
- try {
- include $file;
- } catch (\Exception $e) {
- echo $e;
- }
- return \ob_get_clean();
- }
- if(!defined('GLOBAL_START'))
- {
- Worker::runAll();
- }
|