summaryrefslogtreecommitdiff
path: root/sapi/cli
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/cli')
-rw-r--r--sapi/cli/config.m48
-rw-r--r--sapi/cli/getopt.c4
-rw-r--r--sapi/cli/php.1.in2
-rw-r--r--sapi/cli/php_cli.c21
-rw-r--r--sapi/cli/php_cli_readline.c4
-rw-r--r--sapi/cli/php_cli_readline.h4
-rw-r--r--sapi/cli/php_getopt.h4
-rw-r--r--sapi/cli/tests/009.phpt3
-rw-r--r--sapi/cli/tests/015.phpt8
-rw-r--r--sapi/cli/tests/021.phpt39
-rw-r--r--sapi/cli/tests/022.inc14
-rw-r--r--sapi/cli/tests/022.phpt47
12 files changed, 126 insertions, 32 deletions
diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4
index 4ea165c46..104b1a733 100644
--- a/sapi/cli/config.m4
+++ b/sapi/cli/config.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.22.2.1.2.1 2007/07/11 23:20:36 jani Exp $
+dnl $Id: config.m4,v 1.22.2.1.2.2 2008/09/01 13:15:15 dmitry Exp $
dnl
PHP_ARG_ENABLE(cli,,
@@ -14,7 +14,11 @@ if test "$PHP_CLI" != "no"; then
case $host_alias in
*aix*)
- BUILD_CLI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
+ if test "$php_build_target" = "shared"; then
+ BUILD_CLI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/.libs\/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
+ else
+ BUILD_CLI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
+ fi
;;
*darwin*)
BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c
index 5b0bc5448..bf9012b52 100644
--- a/sapi/cli/getopt.c
+++ b/sapi/cli/getopt.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: getopt.c,v 1.8.2.1.2.7 2007/12/31 07:20:16 sebastian Exp $ */
+/* $Id: getopt.c,v 1.8.2.1.2.8 2008/12/31 11:17:49 sebastian Exp $ */
#include <stdio.h>
#include <string.h>
diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in
index 9e78fef11..a21239942 100644
--- a/sapi/cli/php.1.in
+++ b/sapi/cli/php.1.in
@@ -400,7 +400,7 @@ contributors all around the world.
.SH VERSION INFORMATION
This manpage describes \fBphp\fP, version @PHP_VERSION@.
.SH COPYRIGHT
-Copyright \(co 1997\-2008 The PHP Group
+Copyright \(co 1997\-2009 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.c b/sapi/cli/php_cli.c
index fa3d582bc..813485e43 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| 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 |
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli.c,v 1.129.2.13.2.24 2008/01/29 20:01:14 dmitry Exp $ */
+/* $Id: php_cli.c,v 1.129.2.13.2.30 2008/12/31 11:17:49 sebastian Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -260,11 +260,10 @@ static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{
{
ret = sapi_cli_single_write(ptr, remaining);
if (!ret) {
-#ifdef PHP_CLI_WIN32_NO_CONSOLE
- break;
-#else
+#ifndef PHP_CLI_WIN32_NO_CONSOLE
php_handle_aborted_connection();
#endif
+ break;
}
ptr += ret;
remaining -= ret;
@@ -504,7 +503,7 @@ static void cli_register_file_handles(TSRMLS_D) /* {{{ */
if (s_err) php_stream_close(s_err);
return;
}
-
+
#if PHP_DEBUG
/* do not close stdout and stderr */
s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
@@ -562,7 +561,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
/* #!php support */
c = fgetc(file_handle->handle.fp);
if (c == '#') {
- while (c != '\n' && c != '\r') {
+ while (c != '\n' && c != '\r' && c != EOF) {
c = fgetc(file_handle->handle.fp); /* skip to end of line */
}
/* handle situations where line is terminated by \r\n */
@@ -729,12 +728,6 @@ int main(int argc, char *argv[])
CG(in_compilation) = 0; /* not initialized but needed for several options */
EG(uninitialized_zval_ptr) = NULL;
- if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) {
- PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
- exit_status=1;
- goto out_err;
- }
-
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
switch (c) {
@@ -779,7 +772,7 @@ int main(int argc, char *argv[])
}
request_started = 1;
- php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2008 The PHP Group\n%s",
+ php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2009 The PHP Group\n%s",
PHP_VERSION, sapi_module.name, __DATE__, __TIME__,
#if ZEND_DEBUG && defined(HAVE_GCOV)
"(DEBUG GCOV)",
diff --git a/sapi/cli/php_cli_readline.c b/sapi/cli/php_cli_readline.c
index 614ee26f3..dd76c3518 100644
--- a/sapi/cli/php_cli_readline.c
+++ b/sapi/cli/php_cli_readline.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| 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 |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli_readline.c,v 1.3.2.5.2.4 2007/12/31 07:20:16 sebastian Exp $ */
+/* $Id: php_cli_readline.c,v 1.3.2.5.2.5 2008/12/31 11:17:49 sebastian Exp $ */
#include "php.h"
diff --git a/sapi/cli/php_cli_readline.h b/sapi/cli/php_cli_readline.h
index b5e489aed..cdf4e5a08 100644
--- a/sapi/cli/php_cli_readline.h
+++ b/sapi/cli/php_cli_readline.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli_readline.h,v 1.2.2.1.2.2 2007/12/31 07:20:16 sebastian Exp $ */
+/* $Id: php_cli_readline.h,v 1.2.2.1.2.3 2008/12/31 11:17:49 sebastian Exp $ */
#include "php.h"
diff --git a/sapi/cli/php_getopt.h b/sapi/cli/php_getopt.h
index 0c8e06829..ef10db00c 100644
--- a/sapi/cli/php_getopt.h
+++ b/sapi/cli/php_getopt.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| 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 |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_getopt.h,v 1.7.2.1.2.2 2007/12/31 07:20:16 sebastian Exp $ */
+/* $Id: php_getopt.h,v 1.7.2.1.2.3 2008/12/31 11:17:49 sebastian Exp $ */
#include "php.h"
diff --git a/sapi/cli/tests/009.phpt b/sapi/cli/tests/009.phpt
index c0bb319f7..a881a0730 100644
--- a/sapi/cli/tests/009.phpt
+++ b/sapi/cli/tests/009.phpt
@@ -7,15 +7,12 @@ using invalid combinations of cmdline options
$php = getenv('TEST_PHP_EXECUTABLE');
-var_dump(`$php -n -c -r "echo hello;"`);
var_dump(`$php -n -a -r "echo hello;"`);
var_dump(`$php -n -r "echo hello;" -a`);
echo "Done\n";
?>
--EXPECTF--
-You cannot use both -n and -c switch. Use -h for help.
-NULL
Either execute direct code, process stdin or use a file.
NULL
Either execute direct code, process stdin or use a file.
diff --git a/sapi/cli/tests/015.phpt b/sapi/cli/tests/015.phpt
index 4d5226759..ab5918b4d 100644
--- a/sapi/cli/tests/015.phpt
+++ b/sapi/cli/tests/015.phpt
@@ -13,10 +13,10 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
$php = getenv('TEST_PHP_EXECUTABLE');
-echo `"$php" --version | grep built:`;
-echo `echo "<?php print_r(\\\$argv);" | "$php" -- foo bar baz`, "\n";
-echo `"$php" --version foo bar baz | grep built:`;
-echo `"$php" --notexisting foo bar baz | grep Usage:`;
+echo `"$php" -n --version | grep built:`;
+echo `echo "<?php print_r(\\\$argv);" | "$php" -n -- foo bar baz`, "\n";
+echo `"$php" -n --version foo bar baz | grep built:`;
+echo `"$php" -n --notexisting foo bar baz | grep Usage:`;
echo "Done\n";
?>
diff --git a/sapi/cli/tests/021.phpt b/sapi/cli/tests/021.phpt
new file mode 100644
index 000000000..b127b8969
--- /dev/null
+++ b/sapi/cli/tests/021.phpt
@@ -0,0 +1,39 @@
+--TEST--
+CLI shell shebang
+--SKIPIF--
+<?php
+include 'skipif.inc';
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die ("skip not for Windows");
+}
+?>
+--FILE--
+<?php
+
+$php = getenv('TEST_PHP_EXECUTABLE');
+
+$filename = dirname(__FILE__).'/021.tmp.php';
+
+$script = "#!$php -n\n".
+ "ola\n".
+ "<?php echo 1+1,'\n';\n".
+ "?>\n".
+ "adeus\n";
+
+file_put_contents($filename, $script);
+chmod($filename, 0777);
+
+echo `$filename`;
+
+echo "\nDone\n";
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__).'/021.tmp.php');
+?>
+--EXPECTF--
+ola
+2
+adeus
+
+Done
diff --git a/sapi/cli/tests/022.inc b/sapi/cli/tests/022.inc
new file mode 100644
index 000000000..b77512fcf
--- /dev/null
+++ b/sapi/cli/tests/022.inc
@@ -0,0 +1,14 @@
+<?php
+
+ob_start();
+var_dump(STDIN);
+
+$fd = fopen("php://stdin","r");
+var_dump($fd);
+
+$client_socket = stream_socket_accept($fd);
+
+$data = ob_get_clean();
+fwrite($client_socket, $data);
+
+?>
diff --git a/sapi/cli/tests/022.phpt b/sapi/cli/tests/022.phpt
new file mode 100644
index 000000000..eabb8bdf8
--- /dev/null
+++ b/sapi/cli/tests/022.phpt
@@ -0,0 +1,47 @@
+--TEST--
+STDIN/OUT/ERR stream type
+--SKIPIF--
+<?php
+if (!getenv("TEST_PHP_EXECUTABLE")) die("skip TEST_PHP_EXECUTABLE not set");
+if (substr(PHP_OS, 0, 3) == "WIN") die("skip non windows test");
+?>
+--FILE--
+<?php
+$php = getenv("TEST_PHP_EXECUTABLE");
+$socket_file = dirname(__FILE__) . '/' . pathinfo(__FILE__, PATHINFO_FILENAME) . '.sock';
+$test_file = dirname(__FILE__) . '/' . pathinfo(__FILE__, PATHINFO_FILENAME) . '.inc';
+if (file_exists($socket_file)) {
+ unlink($socket_file);
+}
+$socket = stream_socket_server('unix://' . $socket_file);
+var_dump($socket);
+if (!$socket) {
+ exit(1);
+}
+$desc = array(
+ 0 => $socket,
+ 1 => STDOUT,
+ 2 => STDERR,
+);
+$pipes = array();
+$proc = proc_open("$php -n " . escapeshellarg($test_file), $desc, $pipes);
+var_dump($proc);
+if (!$proc) {
+ exit(1);
+}
+
+$client_socket = stream_socket_client('unix://' . $socket_file);
+var_dump($client_socket);
+echo stream_get_contents($client_socket);
+fclose($client_socket);
+
+proc_terminate($proc);
+proc_close($proc);
+unlink($socket_file);
+?>
+--EXPECTF--
+resource(%d) of type (stream)
+resource(%d) of type (process)
+resource(%d) of type (stream)
+resource(%d) of type (stream)
+resource(%d) of type (stream)