安装方法
.....
- npm install --save node-php-server
使用例子
- var phpServer = require('node-php-server');
- // Create a PHP Server
- phpServer.createServer({
- port: 8000,
- hostname: '127.0.0.1',
- base: '.',
- keepalive: false,
- open: false,
- bin: 'php',
- router: __dirname + '/server.php'
- });
- // Close server
- phpServer.close();
service.php
- <?php
- // Example from Laravel framework
- return call_user_func(function () {
- $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
- $publicDir = __DIR__ . '/public';
- $uri = urldecode($uri);
- $requested = $publicDir . '/' . $uri;
- if ($uri !== '/' && file_exists($requested)) {
- return false;
- }
- require_once $publicDir . '/index.php';
- });
github地址
https://github.com/jaceju/node-php-server
转载请注明:谷谷点程序 » node.js php service安装方法