PHP Classes

File: bin/httpd

Recommend this page to a friend!
  Classes of Lukasz Cepowski   Mock HTTP Server   bin/httpd   Download  
File: bin/httpd
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Mock HTTP Server
Setup and start a HTTP server for testing purposes
Author: By
Last change:
Date: 11 years ago
Size: 1,101 bytes
 

Contents

Class file image Download
#!/usr/bin/env php <?php declare(ticks = 1); error_reporting(E_ALL); set_time_limit(0); ob_implicit_flush(); require_once 'http.php'; $server = new HttpServer(); function sig_handler($signo) { global $server; $server->kill(); } pcntl_signal(SIGTERM, 'sig_handler'); pcntl_signal(SIGINT, 'sig_handler'); $longopts = array( 'port:', 'webdir:', 'pidfile:' ); if (strpos(phpversion(), '5.2.') !== false) { $options = @getopt('p:w:P:'); } else { $options = @getopt('p:w:P:', $longopts); } $port = 1080; if (isset($options['p'])) { $port = (int) $options['p']; } else if (isset($options['port'])) { $port = (int) $options['port']; } $webdir = dirname(dirname(__FILE__)).'/web'; if (isset($options['w'])) { $webdir = $options['w']; } else if (isset($options['webdir'])) { $webdir = $options['webdir']; } if (isset($options['P'])) { @file_put_contents($options['P'], getmypid()); } else if (isset($options['pidfile'])) { @file_put_contents($options['pidfile'], getmypid()); } $server ->setPort($port) ->setWebDir(realpath($webdir)) ->run();