@@ -48,6 +48,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_get_status, 0, 0, 0)
4848 ZEND_ARG_INFO (0 , fetch_scripts )
4949ZEND_END_ARG_INFO ()
5050
51+ ZEND_BEGIN_ARG_INFO_EX (arginfo_opcache_compile_file , 0 , 0 , 1 )
52+ ZEND_ARG_INFO (0 , file )
53+ ZEND_END_ARG_INFO ()
54+
5155ZEND_BEGIN_ARG_INFO_EX (arginfo_opcache_invalidate , 0 , 0 , 1 )
5256 ZEND_ARG_INFO (0 , script )
5357 ZEND_ARG_INFO (0 , force )
@@ -59,12 +63,14 @@ static ZEND_FUNCTION(opcache_invalidate);
5963
6064/* Private functions */
6165static ZEND_FUNCTION (opcache_get_status );
66+ static ZEND_FUNCTION (opcache_compile_file );
6267static ZEND_FUNCTION (opcache_get_configuration );
6368
6469static zend_function_entry accel_functions [] = {
6570 /* User functions */
6671 ZEND_FE (opcache_reset , arginfo_opcache_none )
6772 ZEND_FE (opcache_invalidate , arginfo_opcache_invalidate )
73+ ZEND_FE (opcache_compile_file , arginfo_opcache_compile_file )
6874 /* Private functions */
6975 ZEND_FE (opcache_get_configuration , arginfo_opcache_none )
7076 ZEND_FE (opcache_get_status , arginfo_opcache_get_status )
@@ -709,3 +715,44 @@ static ZEND_FUNCTION(opcache_invalidate)
709715 RETURN_FALSE ;
710716 }
711717}
718+
719+ static ZEND_FUNCTION (opcache_compile_file )
720+ {
721+ char * script_name ;
722+ int script_name_len ;
723+ zend_file_handle handle ;
724+ zend_op_array * op_array = NULL ;
725+ zend_execute_data * orig_execute_data = NULL ;
726+
727+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & script_name , & script_name_len ) == FAILURE ) {
728+ return ;
729+ }
730+
731+ if (!ZCG (enabled ) || !accel_startup_ok || !ZCSG (accelerator_enabled )) {
732+ zend_error (E_NOTICE , ACCELERATOR_PRODUCT_NAME " seems to be disabled, can't compile file" );
733+ RETURN_FALSE ;
734+ }
735+
736+ handle .filename = script_name ;
737+ handle .free_filename = 0 ;
738+ handle .opened_path = NULL ;
739+ handle .type = ZEND_HANDLE_FILENAME ;
740+
741+ orig_execute_data = EG (current_execute_data );
742+
743+ zend_try {
744+ op_array = persistent_compile_file (& handle , ZEND_INCLUDE TSRMLS_CC );
745+ } zend_catch {
746+ EG (current_execute_data ) = orig_execute_data ;
747+ zend_error (E_WARNING , ACCELERATOR_PRODUCT_NAME " could not compile file %s" TSRMLS_CC , handle .filename );
748+ } zend_end_try ();
749+
750+ if (op_array != NULL ) {
751+ destroy_op_array (op_array TSRMLS_CC );
752+ efree (op_array );
753+ RETVAL_TRUE ;
754+ } else {
755+ RETVAL_FALSE ;
756+ }
757+ zend_destroy_file_handle (& handle TSRMLS_CC );
758+ }
0 commit comments