Re: [PHP-CVS] com php-src: Added function opcache_compile_file() to load PHP scripts into cache without execution.: NEWS ext/opcache/ZendAccelerator.c ext/opcache/ZendAccelerator.h ext/opcache/zend_ac

2013-09-25 Thread Yasuo Ohgaki
Hi Adam and Dmitry,

On Thu, Sep 26, 2013 at 5:58 AM, Dmitry Stogov  wrote:

> This function is going to be used only for cache warm-up (to load files
> into cache without execution).
> I don't think it may be useful in application code.
> It 's not a big problem having warning and hiding it with @ if necessary.
>

Rails has feature called "eager loading" that loads all scripts at start up
for better user experience with applications.

This could be used implement the same feature in PHP if it's available
in user space. Since this is ZEND_FUNCTION, I suppose it is available.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net


Re: [PHP-CVS] com php-src: Added function opcache_compile_file() to load PHP scripts into cache without execution.: NEWS ext/opcache/ZendAccelerator.c ext/opcache/ZendAccelerator.h ext/opcache/zend_ac

2013-09-25 Thread Dmitry Stogov
This function is going to be used only for cache warm-up (to load files
into cache without execution).
I don't think it may be useful in application code.
It 's not a big problem having warning and hiding it with @ if necessary.

Thanks. Dmitry.


On Wed, Sep 25, 2013 at 8:06 PM, Adam Harvey  wrote:

> On 25 September 2013 01:14, Dmitry Stogov  wrote:
> > +   zend_try {
> > +   op_array = persistent_compile_file(&handle, ZEND_INCLUDE
> TSRMLS_CC);
> > +   } zend_catch {
> > +   EG(current_execute_data) = orig_execute_data;
> > +   zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could
> not compile file %s" TSRMLS_CC, handle.filename);
> > +   } zend_end_try();
>
> I'm writing the documentation for this, and I'm wondering: does the
> warning serve any purpose here? Is there an intended situation where
> opcache_compile_file() would return false and wouldn't generate a
> warning? (I can see some code paths in persistent_compile_file() that
> probably result in that, but I don't know how intentional that is.)
>
> If there isn't, I'm thinking it would be better to just return false
> without the warning — users who are doing error handling and have
> error reporting on don't need to use @ in that case. I know that's a
> constant irritant for me when I'm writing code that uses fopen(), for
> instance. :)
>
> Adam
>


Re: [PHP-CVS] com php-src: Added function opcache_compile_file() to load PHP scripts into cache without execution.: NEWS ext/opcache/ZendAccelerator.c ext/opcache/ZendAccelerator.h ext/opcache/zend_ac

2013-09-25 Thread Adam Harvey
On 25 September 2013 01:14, Dmitry Stogov  wrote:
> +   zend_try {
> +   op_array = persistent_compile_file(&handle, ZEND_INCLUDE 
> TSRMLS_CC);
> +   } zend_catch {
> +   EG(current_execute_data) = orig_execute_data;
> +   zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could not 
> compile file %s" TSRMLS_CC, handle.filename);
> +   } zend_end_try();

I'm writing the documentation for this, and I'm wondering: does the
warning serve any purpose here? Is there an intended situation where
opcache_compile_file() would return false and wouldn't generate a
warning? (I can see some code paths in persistent_compile_file() that
probably result in that, but I don't know how intentional that is.)

If there isn't, I'm thinking it would be better to just return false
without the warning — users who are doing error handling and have
error reporting on don't need to use @ in that case. I know that's a
constant irritant for me when I'm writing code that uses fopen(), for
instance. :)

Adam

--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] com php-src: Added function opcache_compile_file() to load PHP scripts into cache without execution.: NEWS ext/opcache/ZendAccelerator.c ext/opcache/ZendAccelerator.h ext/opcache/zend_accele

2013-09-25 Thread Dmitry Stogov
Commit:69454d9f0f765416f245acbc626b3984dcbf5e1d
Author:Dmitry Stogov  Wed, 25 Sep 2013 12:14:06 
+0400
Parents:   dc8705c256cd1d50cfa276e8de31558e089eab92
Branches:  PHP-5.5 master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=69454d9f0f765416f245acbc626b3984dcbf5e1d

Log:
Added function opcache_compile_file() to load PHP scripts into cache without 
execution.

Changed paths:
  M  NEWS
  M  ext/opcache/ZendAccelerator.c
  M  ext/opcache/ZendAccelerator.h
  M  ext/opcache/zend_accelerator_module.c


Diff:
diff --git a/NEWS b/NEWS
index cd4d377..bdc0cd5 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@ PHP   
 NEWS
 imap). (ryotakatsuki at gmail dot com)
 
 - OPcache:
+  . Added function opcache_compile_file() to load PHP scripts into cache
+without execution. (Julien)
   . Fixed bug #65665 (Exception not properly caught when opcache enabled).
 (Laruence)
   . Fixed bug #65510 (5.5.2 crashes in _get_zval_ptr_ptr_var). (Dmitry)
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 7fdae6f..72b5a1b 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -1446,7 +1446,7 @@ static zend_persistent_script 
*compile_and_cache_file(zend_file_handle *file_han
 }
 
 /* zend_compile() replacement */
-static zend_op_array *persistent_compile_file(zend_file_handle *file_handle, 
int type TSRMLS_DC)
+zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type 
TSRMLS_DC)
 {
zend_persistent_script *persistent_script = NULL;
char *key = NULL;
diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h
index 361b60b..f223f12 100644
--- a/ext/opcache/ZendAccelerator.h
+++ b/ext/opcache/ZendAccelerator.h
@@ -325,6 +325,7 @@ int  accelerator_shm_read_lock(TSRMLS_D);
 void accelerator_shm_read_unlock(TSRMLS_D);
 
 char *accel_make_persistent_key_ex(zend_file_handle *file_handle, int 
path_length, int *key_len TSRMLS_DC);
+zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type 
TSRMLS_DC);
 
 #if !defined(ZEND_DECLARE_INHERITED_CLASS_DELAYED)
 # define ZEND_DECLARE_INHERITED_CLASS_DELAYED 145
diff --git a/ext/opcache/zend_accelerator_module.c 
b/ext/opcache/zend_accelerator_module.c
index f9ddaa9..dedb721 100644
--- a/ext/opcache/zend_accelerator_module.c
+++ b/ext/opcache/zend_accelerator_module.c
@@ -48,6 +48,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_get_status, 0, 0, 0)
ZEND_ARG_INFO(0, fetch_scripts)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_compile_file, 0, 0, 1)
+   ZEND_ARG_INFO(0, file)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_invalidate, 0, 0, 1)
ZEND_ARG_INFO(0, script)
ZEND_ARG_INFO(0, force)
@@ -59,12 +63,14 @@ static ZEND_FUNCTION(opcache_invalidate);
 
 /* Private functions */
 static ZEND_FUNCTION(opcache_get_status);
+static ZEND_FUNCTION(opcache_compile_file);
 static ZEND_FUNCTION(opcache_get_configuration);
 
 static zend_function_entry accel_functions[] = {
/* User functions */
ZEND_FE(opcache_reset,  
arginfo_opcache_none)
ZEND_FE(opcache_invalidate, 
arginfo_opcache_invalidate)
+   ZEND_FE(opcache_compile_file,   
arginfo_opcache_compile_file)
/* Private functions */
ZEND_FE(opcache_get_configuration,  arginfo_opcache_none)
ZEND_FE(opcache_get_status, 
arginfo_opcache_get_status)
@@ -709,3 +715,44 @@ static ZEND_FUNCTION(opcache_invalidate)
RETURN_FALSE;
}
 }
+
+static ZEND_FUNCTION(opcache_compile_file)
+{
+   char *script_name;
+   int script_name_len;
+   zend_file_handle handle;
+   zend_op_array *op_array = NULL;
+   zend_execute_data *orig_execute_data = NULL;
+
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &script_name, 
&script_name_len) == FAILURE) {
+   return;
+   }
+
+   if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
+   zend_error(E_NOTICE, ACCELERATOR_PRODUCT_NAME " seems to be 
disabled, can't compile file");
+   RETURN_FALSE;
+   }
+
+   handle.filename = script_name;
+   handle.free_filename = 0;
+   handle.opened_path = NULL;
+   handle.type = ZEND_HANDLE_FILENAME;
+
+   orig_execute_data = EG(current_execute_data);
+
+   zend_try {
+   op_array = persistent_compile_file(&handle, ZEND_INCLUDE 
TSRMLS_CC);
+   } zend_catch {
+   EG(current_execute_data) = orig_execute_data;
+   zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could not 
compile file %s" TSRMLS_CC, handle.filename);
+   } zend_end_try();
+
+   if(op_array != NULL) {
+   destroy_op_array(op_array TSRMLS_CC);
+   efree(op_array);

[PHP-CVS] com php-src: Merge branch 'PHP-5.5': ext/opcache/ZendAccelerator.c ext/opcache/ZendAccelerator.h

2013-09-25 Thread Dmitry Stogov
Commit:6daa04a4f606f8121d9f1ea6cd90c1c8a684500e
Author:Dmitry Stogov  Wed, 25 Sep 2013 12:15:01 
+0400
Parents:   4e249c8a932675e5aceeb52c3ff6f6465d8a8ed1 
69454d9f0f765416f245acbc626b3984dcbf5e1d
Branches:  master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=6daa04a4f606f8121d9f1ea6cd90c1c8a684500e

Log:
Merge branch 'PHP-5.5'

* PHP-5.5:
  Added function opcache_compile_file() to load PHP scripts into cache without 
execution.

Conflicts:
NEWS

Changed paths:
  MM  ext/opcache/ZendAccelerator.c
  MM  ext/opcache/ZendAccelerator.h


Diff:



--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] com php-src: Merge branch 'PHP-5.5': ext/opcache/ZendAccelerator.c

2013-09-25 Thread Dmitry Stogov
Commit:4e249c8a932675e5aceeb52c3ff6f6465d8a8ed1
Author:Dmitry Stogov  Wed, 25 Sep 2013 11:04:03 
+0400
Parents:   8d087dc0d7c88e26539646875dc0f7bb5042187b 
dc8705c256cd1d50cfa276e8de31558e089eab92
Branches:  master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=4e249c8a932675e5aceeb52c3ff6f6465d8a8ed1

Log:
Merge branch 'PHP-5.5'

* PHP-5.5:
  Fixed issue #135 (segfault in interned strings if initial memory is too low)

Conflicts:
NEWS

Bugs:
https://bugs.php.net/135

Changed paths:
  MM  ext/opcache/ZendAccelerator.c


Diff:



--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] com php-src: Fixed issue #135 (segfault in interned strings if initial memory is too low): NEWS ext/opcache/ZendAccelerator.c

2013-09-25 Thread Dmitry Stogov
Commit:dc8705c256cd1d50cfa276e8de31558e089eab92
Author:Dmitry Stogov  Wed, 25 Sep 2013 11:02:39 
+0400
Parents:   f7eff9cd41e0b996af9a0a01d3c5f8fdd8b7fa60
Branches:  PHP-5.5 master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=dc8705c256cd1d50cfa276e8de31558e089eab92

Log:
Fixed issue #135 (segfault in interned strings if initial memory is too low)

Bugs:
https://bugs.php.net/135

Changed paths:
  M  NEWS
  M  ext/opcache/ZendAccelerator.c


Diff:
diff --git a/NEWS b/NEWS
index e02d1b9..cd4d377 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,8 @@ PHP   
 NEWS
   . Fixed bug #65665 (Exception not properly caught when opcache enabled).
 (Laruence)
   . Fixed bug #65510 (5.5.2 crashes in _get_zval_ptr_ptr_var). (Dmitry)
+  . Fixed issue #135 (segfault in interned strings if initial memory is too
+low). (Julien)
 
 - SPL:
   . Fix bug #64782 (SplFileObject constructor make $context optional / give it
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 827f047..7fdae6f 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -2407,14 +2407,14 @@ static inline int accel_find_sapi(TSRMLS_D)
return FAILURE;
 }
 
-static void zend_accel_init_shm(TSRMLS_D)
+static int zend_accel_init_shm(TSRMLS_D)
 {
zend_shared_alloc_lock(TSRMLS_C);
 
accel_shared_globals = 
zend_shared_alloc(sizeof(zend_accel_shared_globals));
if (!accel_shared_globals) {
zend_accel_error(ACCEL_LOG_FATAL, "Insufficient shared 
memory!");
-   return;
+   return FAILURE;
}
ZSMMG(app_shared_globals) = accel_shared_globals;
 
@@ -2429,7 +2429,8 @@ static void zend_accel_init_shm(TSRMLS_D)
ZCSG(interned_strings).arBuckets = 
zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(Bucket *));
ZCSG(interned_strings_start) = 
zend_shared_alloc((ZCG(accel_directives).interned_strings_buffer * 1024 * 
1024));
if (!ZCSG(interned_strings).arBuckets || !ZCSG(interned_strings_start)) 
{
-   zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " cannot allocate 
buffer for interned strings");
+   zend_accel_error(ACCEL_LOG_FATAL, ACCELERATOR_PRODUCT_NAME " 
cannot allocate buffer for interned strings");
+   return FAILURE;
}
ZCSG(interned_strings_end)   = ZCSG(interned_strings_start) + 
(ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
ZCSG(interned_strings_top)   = ZCSG(interned_strings_start);
@@ -2468,6 +2469,8 @@ static void zend_accel_init_shm(TSRMLS_D)
ZCSG(restart_in_progress) = 0;
 
zend_shared_alloc_unlock(TSRMLS_C);
+
+   return SUCCESS;
 }
 
 static void accel_globals_ctor(zend_accel_globals *accel_globals TSRMLS_DC)
@@ -2525,7 +2528,10 @@ static int accel_startup(zend_extension *extension)
 //
switch 
(zend_shared_alloc_startup(ZCG(accel_directives).memory_consumption)) {
case ALLOC_SUCCESS:
-   zend_accel_init_shm(TSRMLS_C);
+   if (zend_accel_init_shm(TSRMLS_C) == FAILURE) {
+   accel_startup_ok = 0;
+   return FAILURE;
+   }
break;
case ALLOC_FAILURE:
accel_startup_ok = 0;


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php