Giter Site home page Giter Site logo

php-built-in-web-server-router's Introduction

Use this only in a development environment

PHP-Built-in-web-server-Router

PHP-Built-in-web-server-Router PHP-Built-in-web-server-Router

This library comes with caching support for PHP built-in web-server

Router.php is loaded before index.php, so you can:

  • Have CORS enabled
  • Set up your environment variables and constants
  • And CACHE EVERYTHING

It also comes with a custom console function to output string|array into terminal ( check out index.php for usage ).

Don't forget to delete it after usage, this function is meant only for Development !

console_output( $string , 'another', array('show'=>1) , ...args )

NODE.JS

I highly recommend node-php-awesome-server if you need a php webserver in a node environment, it uses this router as default router, and much more various configuration options.

npm install node-php-awesome-server --save-dev

If you install this as a npm package you can only retrieve the absolute paths of the router, the library file and a cURL certificate.

npm install php-built-in-web-server-router --save-dev
let router = require('php-built-in-web-server-router');

console.log('Router path: ', router.path);
console.log('Router library: ', router.lib);
console.log('cURL certificate: ', router.cert);

Requirements

PHP 5.4.0+ and /src/mimes.json file.

Usage

Bellow you'll find a few examples. Additional params may be found here

  1. If router.php is located in the root folder
php -S localhost:8000 router.php
  1. If router.php is located in separate folder:
php -S localhost:8000 misc/router.php
  1. If your project structure is something like this, use '-t' parameter to set the document root to your public folder
./www/
    - your_php_framework/
        - private_framework_stuff/
          ...
        - public/
    - misc/
        - router.php
        - mimes.json
    - onefile.php
    
    
 php -S localhost:8000 -t ./your_php_framework/public misc/router.php 

Edit router.php

This are the default settings.

# class PHP_Webserver_Router{...}
#    or   

include('router.class.php');
    
###
# Set up early your environment variables/constants
###
    
$_SERVER["ENVIRONMENT"] = "development";
error_reporting(E_ALL);

 
$php_web_server = new PHP_Webserver_Router();

    
###
# Uncomment to Disable http output in console:
###
//$php_web_server->log_enable = FALSE;

###
# Change this if your "index.php" has another name. By default is index.php
###
//$php_web_server->indexPath = "my_new_index_file.php";

return $php_web_server->listen();

Notes

I've tested this with the following php frameworks:

  • Slim 3 ( the newest addition to this list )
  • Yii2
  • CodeIgniter 3
  • Wordpress 4
  • Drupal 7 and 8

On the first request sent to router.php, it will attempt to download and create mimes.json, if that fails, you can find mimes.json in ./src/ and copy it next to router.php

Personally I bind the webserver to php -S 0.0.0.0 ... so I can test from other remote devices.

Thanks

The method create_mime_file() is a modified version of Josh Sean's generateUpToDateMimeArray function

php-built-in-web-server-router's People

Contributors

darklightcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

php-built-in-web-server-router's Issues

suggections

i started using this router for test about 2 weeks ago cause apache crashed, tbh this is a really good router for php, but the code is not organized, you should split the router class into multiply class, a class have 1 job.
you may also use some packages and make it a php cli application.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.