cellog Fri Jun 27 01:21:13 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/phar cgidebug phar.c phar.phar stream.c
/php-src/ext/phar/tests 017.phpt
/php-src/ext/phar/tests/tar tar_bz2.phpt
/php-src/ext/phar/tests/zip phar_magic.phpt
Log:
in preparation for a performance optimization that involves
eliminating phar's interception of zend_compile in favor of a new to-be-added
hook in PHP 5.3+,
allow "include 'phar:///path/to/my.phar';" to work as equivalent to
php /path/to/my.phar
this slight change in scripting still allows inclusion and execution of phar
stub, but removes the need to
check and modify path in zend_compile, which allows us to play much nicer
with external tools like
debuggers/opcode caches
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/cgidebug?r1=1.3.2.2&r2=1.3.2.3&diff_format=u
Index: php-src/ext/phar/cgidebug
diff -u php-src/ext/phar/cgidebug:1.3.2.2 php-src/ext/phar/cgidebug:1.3.2.3
--- php-src/ext/phar/cgidebug:1.3.2.2 Sun Jun 22 00:50:32 2008
+++ php-src/ext/phar/cgidebug Fri Jun 27 01:21:12 2008
@@ -1,11 +1,11 @@
#!/bin/sh
-export SCRIPT_NAME=/frontcontroller9.php
-export PATH_INFO=/hi
-export
SCRIPT_FILENAME=/home/cellog/workspace/php5/ext/phar/tests/cache_list/frontcontroller9.php
-export
PATH_TRANSLATED=/home/cellog/workspace/php5/ext/phar/tests/cache_list/frontcontroller9.php
+export SCRIPT_NAME=/front.phar.php
+export PATH_INFO=/index.php
+export
SCRIPT_FILENAME=/home/cellog/workspace/php5/ext/phar/tests/front.phar.php
+export
PATH_TRANSLATED=/home/cellog/workspace/php5/ext/phar/tests/front.phar.php
export REDIRECT_STATUS=1
export REQUEST_METHOD=GET
-export REQUEST_URI=/frontcontroller9.php/hi
-cd /home/cellog/workspace/php5/ext/phar/tests/cache_list
-ddd ../../../../sapi/cgi/php-cgi &
+export REQUEST_URI=/front.phar.php/index.php
+cd /home/cellog/workspace/php5
+ddd sapi/cgi/php-cgi &
cd /home/cellog/workspace/php5/ext/phar
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.370.2.29&r2=1.370.2.30&diff_format=u
Index: php-src/ext/phar/phar.c
diff -u php-src/ext/phar/phar.c:1.370.2.29 php-src/ext/phar/phar.c:1.370.2.30
--- php-src/ext/phar/phar.c:1.370.2.29 Mon Jun 23 19:18:01 2008
+++ php-src/ext/phar/phar.c Fri Jun 27 01:21:12 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: phar.c,v 1.370.2.29 2008/06/23 19:18:01 sfox Exp $ */
+/* $Id: phar.c,v 1.370.2.30 2008/06/27 01:21:12 cellog Exp $ */
#define PHAR_MAIN 1
#include "phar_internal.h"
@@ -3187,7 +3187,6 @@
/* compressed phar */
#if PHP_VERSION_ID >= 50300
file_handle->type = ZEND_HANDLE_STREAM;
- file_handle->free_filename = 0;
/* we do our own reading directly from the
phar, don't change the next line */
file_handle->handle.stream.handle = phar;
file_handle->handle.stream.reader =
phar_zend_stream_reader;
@@ -3200,7 +3199,6 @@
memset(&file_handle->handle.stream.mmap, 0,
sizeof(file_handle->handle.stream.mmap));
#else /* PHP_VERSION_ID */
file_handle->type = ZEND_HANDLE_STREAM;
- file_handle->free_filename = 0;
/* we do our own reading directly from the
phar, don't change the next line */
file_handle->handle.stream.handle = phar;
file_handle->handle.stream.reader =
phar_zend_stream_reader;
@@ -3408,7 +3406,7 @@
php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION);
php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION);
- php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.29 $");
+ php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.30 $");
php_info_print_table_row(2, "Phar-based phar archives", "enabled");
php_info_print_table_row(2, "Tar-based phar archives", "enabled");
php_info_print_table_row(2, "ZIP-based phar archives", "enabled");
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.phar?r1=1.7.2.27&r2=1.7.2.28&diff_format=u
Index: php-src/ext/phar/phar.phar
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/stream.c?r1=1.27.2.6&r2=1.27.2.7&diff_format=u
Index: php-src/ext/phar/stream.c
diff -u php-src/ext/phar/stream.c:1.27.2.6 php-src/ext/phar/stream.c:1.27.2.7
--- php-src/ext/phar/stream.c:1.27.2.6 Wed Jun 18 06:38:47 2008
+++ php-src/ext/phar/stream.c Fri Jun 27 01:21:12 2008
@@ -157,6 +157,7 @@
*/
static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, char
*path, char *mode, int options, char **opened_path, php_stream_context *context
STREAMS_DC TSRMLS_DC) /* {{{ */
{
+ phar_archive_data *phar;
phar_entry_data *idata;
char *internal_file;
char *error;
@@ -234,8 +235,55 @@
}
return fpf;
} else {
+ if (!*internal_file && (options & STREAM_OPEN_FOR_INCLUDE)) {
+ /* retrieve the stub */
+ if (FAILURE == phar_get_archive(&phar, resource->host,
host_len, NULL, 0, NULL TSRMLS_CC)) {
+ php_stream_wrapper_log_error(wrapper, options
TSRMLS_CC, "file %s is not a valid phar archive");
+ efree(internal_file);
+ php_url_free(resource);
+ return NULL;
+ }
+ if (phar->is_tar || phar->is_zip) {
+ if ((FAILURE == phar_get_entry_data(&idata,
resource->host, host_len, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0,
&error, 0 TSRMLS_CC)) || !idata) {
+ goto idata_error;
+ }
+ efree(internal_file);
+ if (opened_path) {
+ spprintf(opened_path, MAXPATHLEN, "%s",
phar->fname);
+ }
+ php_url_free(resource);
+ goto phar_stub;
+ } else {
+ phar_entry_info *entry;
+
+ entry = (phar_entry_info *) ecalloc(1,
sizeof(phar_entry_info));
+ entry->is_temp_dir = 1;
+ entry->filename = "";
+ entry->filename_len = 0;
+ entry->phar = phar;
+ entry->offset = entry->offset_abs = 0;
+ entry->compressed_filesize =
entry->uncompressed_filesize = phar->halt_offset;
+ entry->is_crc_checked = 1;
+
+ idata = (phar_entry_data *) ecalloc(1,
sizeof(phar_entry_data));
+ idata->fp = phar_get_pharfp(phar TSRMLS_CC);
+ idata->phar = phar;
+ idata->internal_file = entry;
+ if (!phar->is_persistent) {
+ ++(entry->phar->refcount);
+ }
+ ++(entry->fp_refcount);
+ php_url_free(resource);
+ if (opened_path) {
+ spprintf(opened_path, MAXPATHLEN, "%s",
phar->fname);
+ }
+ efree(internal_file);
+ goto phar_stub;
+ }
+ }
/* read-only access is allowed to magic files in .phar
directory */
if ((FAILURE == phar_get_entry_data(&idata, resource->host,
host_len, internal_file, strlen(internal_file), "r", 0, &error, 0 TSRMLS_CC))
|| !idata) {
+idata_error:
if (error) {
php_stream_wrapper_log_error(wrapper, options
TSRMLS_CC, error);
efree(error);
@@ -283,11 +331,12 @@
PHAR_G(cwd) = NULL;
}
}
- fpf = php_stream_alloc(&phar_ops, idata, NULL, mode);
if (opened_path) {
spprintf(opened_path, MAXPATHLEN, "phar://%s/%s",
idata->phar->fname, idata->internal_file->filename);
}
efree(internal_file);
+phar_stub:
+ fpf = php_stream_alloc(&phar_ops, idata, NULL, mode);
return fpf;
}
/* }}} */
@@ -297,8 +346,14 @@
*/
static int phar_stream_close(php_stream *stream, int close_handle TSRMLS_DC)
/* {{{ */
{
+ phar_entry_info *entry = ((phar_entry_data
*)stream->abstract)->internal_file;
+
phar_entry_delref((phar_entry_data *)stream->abstract TSRMLS_CC);
+ if (entry->is_temp_dir) {
+ /* phar archive stub, free it */
+ efree(entry);
+ }
return 0;
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/017.phpt?r1=1.14&r2=1.14.2.1&diff_format=u
Index: php-src/ext/phar/tests/017.phpt
diff -u php-src/ext/phar/tests/017.phpt:1.14
php-src/ext/phar/tests/017.phpt:1.14.2.1
--- php-src/ext/phar/tests/017.phpt:1.14 Mon Apr 14 15:58:11 2008
+++ php-src/ext/phar/tests/017.phpt Fri Jun 27 01:21:12 2008
@@ -10,17 +10,22 @@
$pname = 'phar://' . $fname;
$file = "<?php
Phar::mapPhar('hio');
+var_dump(__FILE__);
+var_dump(substr(__FILE__, 0, 4) != 'phar');
__HALT_COMPILER(); ?>";
$files = array();
$files['a'] = 'abc';
include 'files/phar_test.inc';
-include $fname;
+include $pname;
$dir = opendir('phar://hio');
?>
--CLEAN--
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') .
'.phar.php'); ?>
--EXPECTF--
+string(%d) "%s017.phar.php"
+bool(true)
+
Warning: opendir(phar://hio): failed to open dir: phar error: no directory in
"phar://hio", must have at least phar://hio/ for root directory (always use
full path to a new phar)
phar url "phar://hio" is unknown in %s017.php on line %d
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/tar/tar_bz2.phpt?r1=1.3.2.1&r2=1.3.2.2&diff_format=u
Index: php-src/ext/phar/tests/tar/tar_bz2.phpt
diff -u php-src/ext/phar/tests/tar/tar_bz2.phpt:1.3.2.1
php-src/ext/phar/tests/tar/tar_bz2.phpt:1.3.2.2
--- php-src/ext/phar/tests/tar/tar_bz2.phpt:1.3.2.1 Fri Jun 13 22:07:44 2008
+++ php-src/ext/phar/tests/tar/tar_bz2.phpt Fri Jun 27 01:21:12 2008
@@ -23,13 +23,16 @@
$tar->mkDir('internal/dir');
$tar->mkDir('dir');
$tar->addFile('.phar/stub.php', '<?php
+var_dump(__FILE__);
+var_dump(substr(__FILE__, 0, 4) != "phar");
Phar::mapPhar();
var_dump("it worked");
include "phar://" . __FILE__ . "/tar_004.php";
+__HALT_COMPILER();
');
$tar->close();
-include $fname;
+include $alias;
$phar = new Phar($fname);
$phar['test'] = 'hi';
@@ -48,6 +51,8 @@
@unlink(dirname(__FILE__) . '/tar_bz2.phar.tar');
?>
--EXPECTF--
+string(%d) "%star_bz2.phar"
+bool(true)
string(9) "it worked"
string(%d) "phar://%star_bz2.phar/tar_004.php"
bool(true)
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/zip/phar_magic.phpt?r1=1.5&r2=1.5.2.1&diff_format=u
Index: php-src/ext/phar/tests/zip/phar_magic.phpt
diff -u php-src/ext/phar/tests/zip/phar_magic.phpt:1.5
php-src/ext/phar/tests/zip/phar_magic.phpt:1.5.2.1
--- php-src/ext/phar/tests/zip/phar_magic.phpt:1.5 Fri May 2 05:05:55 2008
+++ php-src/ext/phar/tests/zip/phar_magic.phpt Fri Jun 27 01:21:12 2008
@@ -8,16 +8,19 @@
--FILE--
<?php
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') .
'.phar.zip.php';
+$pname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') .
'.phar.zip.php';
$p = new Phar($fname);
var_dump($p->isFileFormat(Phar::ZIP));
$p['a'] = '<?php include "b/c.php";' . "\n";
$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo
stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";';
$p['d'] = "in d\n";
$p->setStub('<?php
+var_dump(__FILE__);
+var_dump(substr(__FILE__, 0, 4) != "phar");
set_include_path("phar://" . __FILE__);
include "phar://" . __FILE__ . "/a";
__HALT_COMPILER();');
-include $fname;
+include $pname;
?>
===DONE===
--CLEAN--
@@ -27,6 +30,8 @@
?>
--EXPECTF--
bool(true)
+string(%d) "%sphar_magic.phar.zip.php"
+bool(true)
in b
<?php include "b/c.php";
in d
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php