From cf099ba2ee4e438bae16c3670a14ce0c4390529a Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Fri, 29 Mar 2013 01:32:44 +0100 Subject: Imported Upstream version 5.5.0~beta2 --- sapi/cli/php.1.in | 32 ++++++++++++++++++++++--- sapi/cli/php_cli_server.c | 61 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 74 insertions(+), 19 deletions(-) (limited to 'sapi/cli') diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in index 186b128f8..0e9d07ac7 100644 --- a/sapi/cli/php.1.in +++ b/sapi/cli/php.1.in @@ -1,4 +1,4 @@ -.TH PHP 1 "2010" "The PHP Group" "Scripting Language" +.TH PHP 1 "2013" "The PHP Group" "Scripting Language" .SH NAME php \- PHP Command Line Interface 'CLI' .SH SYNOPSIS @@ -42,6 +42,12 @@ php \- PHP Command Line Interface 'CLI' .LP \fBphp \fP[options] \fB\-a\fP .LP +.B php +[options] \-S +.IR addr:port +[\-t +.IR docroot ] +.LP .SH DESCRIPTION \fBPHP\fP is a widely\-used general\-purpose scripting language that is especially suited for Web development and can be embedded into HTML. This is the command line interface @@ -78,7 +84,13 @@ and therefore reading from .B STDIN explicitly changes the next input line or skips input lines. .LP -If none of \-r \-f \-B \-R \-F or \-E is present but a single parameter is given +PHP also contains an embedded web server for application development purpose. By using the \-S option where +.B addr:port +point to a local address and port PHP will listen to HTTP requests on that address and port and serve files from the current working directory or the +.B docroot +passed by the \-t option. +.LP +If none of \-r \-f \-B \-R \-F \-E or \-S is present but a single parameter is given then this parameter is taken as the filename to parse and execute (same as with \-f). If no parameter is present then the standard input is read and executed. @@ -263,6 +275,20 @@ after processing all input lines Output HTML syntax highlighted source .TP .PD 0 +.B \-\-server \fIaddr:port\fP +.TP +.PD 1 +.B \-S \fIaddr:port\fP +Start embedded Webserver on the given local address and port +.TP +.PD 0 +.B \-\-docroot \fIdocroot\fP +.TP +.PD 1 +.B \-t \fIdocroot\fP +Specify the document root to be used by the embedded web server +.TP +.PD 0 .B \-\-version .TP .PD 1 @@ -435,7 +461,7 @@ contributors all around the world. .SH VERSION INFORMATION This manpage describes \fBphp\fP, version @PHP_VERSION@. .SH COPYRIGHT -Copyright \(co 1997\-2010 The PHP Group +Copyright \(co 1997\-2013 The PHP Group .LP This source file is subject to version 3.01 of the PHP license, that is bundled with this package in the file LICENSE, and is diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index a2b85d47b..5c9b2e86d 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -24,11 +24,12 @@ #include #ifdef PHP_WIN32 -#include -#include -#include "win32/time.h" -#include "win32/signal.h" -#include "win32/php_registry.h" +# include +# include +# include "win32/time.h" +# include "win32/signal.h" +# include "win32/php_registry.h" +# include #else # include "php_config.h" #endif @@ -296,6 +297,36 @@ static const char php_cli_server_css[] = "\n"; /* }}} */ +#ifdef PHP_WIN32 +int php_cli_server_get_system_time(char *buf) { + struct _timeb system_time; + errno_t err; + + if (buf == NULL) { + return -1; + } + + _ftime(&system_time); + err = ctime_s(buf, 52, &(system_time.time) ); + if (err) { + return -1; + } + return 0; +} +#else +int php_cli_server_get_system_time(char *buf) { + struct timeval tv; + struct tm tm; + + gettimeofday(&tv, NULL); + + /* TODO: should be checked for NULL tm/return vaue */ + php_localtime_r(&tv.tv_sec, &tm); + php_asctime_r(&tm, buf); + return 0; +} +#endif + static void char_ptr_dtor_p(char **p) /* {{{ */ { pefree(*p, 1); @@ -640,13 +671,11 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC) static void sapi_cli_server_log_message(char *msg TSRMLS_DC) /* {{{ */ { - struct timeval tv; - struct tm tm; char buf[52]; - gettimeofday(&tv, NULL); - php_localtime_r(&tv.tv_sec, &tm); - php_asctime_r(&tm, buf); - { + + if (php_cli_server_get_system_time(buf) != 0) { + memmove(buf, "unknown time, can't be fetched", sizeof("unknown time, can't be fetched")); + } else { size_t l = strlen(buf); if (l > 0) { buf[l - 1] = '\0'; @@ -2402,12 +2431,12 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ sapi_module.phpinfo_as_text = 0; { - struct timeval tv; - struct tm tm; char buf[52]; - gettimeofday(&tv, NULL); - php_localtime_r(&tv.tv_sec, &tm); - php_asctime_r(&tm, buf); + + if (php_cli_server_get_system_time(buf) != 0) { + memmove(buf, "unknown time, can't be fetched", sizeof("unknown time, can't be fetched")); + } + printf("PHP %s Development Server started at %s" "Listening on http://%s\n" "Document root is %s\n" -- cgit v1.2.3