Performance Comparison Between require/include and require_once/include_once in PHP

Source: Internet
Author: User
_ Once is slower than non-once, because _ Once adds some condition judgment and searches for it in the Zend internal hash table. It contains only when it cannot be found,
See the http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_def.h for the code section? View = Markup

The key transcript is as follows:

Switch (z_lval (opline-> op2.u. Constant ))...{
Case zend_include_once:
Case zend_require_once :...{
Zend_file_handle file_handle;
Char CWD [MAXPATHLEN];
Cwd_state state;

If (is_absolute_path (z_strval_p (inc_filename), z_strlen_p (inc_filename )))...{
CWD [0] = '';
} Else if (! Vcwd_getcwd (CWD, MAXPATHLEN ))...{
CWD [0] = '';
}

State. cwd_length = strlen (CWD );
State. CWD = zend_strndup (CWD, state. cwd_length );

Failure_retval = (! Virtual_file_ex (& state, z_strval_p (inc_filename), null, 1 )&&
Zend_hash_exists (& EG (included_files), State. CWD, state. cwd_length + 1 ));

Free (State. CWD );

If (failure_retval )...{
/** // * Do nothing */
} Else if (success = zend_stream_open (z_strval_p (inc_filename), & file_handle tsrmls_cc ))...{
If (! File_handle.opened_path )...{
File_handle.opened_path = estrndup (z_strval_p (inc_filename), z_strlen_p (inc_filename ));
}

If (zend_hash_add_empty_element (& EG (included_files), file_handle.opened_path, strlen (file_handle.opened_path) + 1) = success )...{
New_op_array = zend_compile_file (& file_handle, (z_lval (opline-> op2.u. Constant) = zend_include_once? Zend_include: zend_require) tsrmls_cc );
Zend_destroy_file_handle (& file_handle tsrmls_cc );
} Else ...{
Zend_file_handle_dtor (& file_handle );
Failure_retval = 1;
}
} Else ...{
If (z_lval (opline-> op2.u. Constant) = zend_include_once )...{
Zend_message_dispatcher (zmsg_failed_include_fopen, z_strval_p (inc_filename ));
} Else ...{
Zend_message_dispatcher (zmsg_failed_require_fopen, z_strval_p (inc_filename ));
}
}
}
Break;
Case zend_include:
Case zend_require:
New_op_array = compile_filename (z_lval (opline-> op2.u. Constant), inc_filename tsrmls_cc );
Break;
Case zend_eval :...{
Char * eval_desc = zend_make_compiled_string_description ("eval () 'd code" tsrmls_cc );

New_op_array = zend_compile_string (inc_filename, eval_desc tsrmls_cc );
Efree (eval_desc );
}
Break;
Empty_switch_default_case ()
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.