Fix include/require and phar compatibility
@@ -1144,9 +1144,29 @@ SWOW_API php_stream_ops swow_php_stream_stdio_ops;
/* {{{ php_stream_fopen */
SWOW_API php_stream *_swow_stream_fopen(const char *filename, const char *mode, zend_string **opened_path, int options STREAMS_DC)
{
- if (options & STREAM_OPEN_FOR_INCLUDE) {
- return _php_stream_fopen(filename, mode, opened_path, options STREAMS_REL_CC);
+ zend_bool open_for_include = options & STREAM_OPEN_FOR_INCLUDE;
+ /** phar_open_archive_fp, cannot use async-io */
+ if (!open_for_include && EG(current_execute_data) && EG(current_execute_data)->func &&
+ ZEND_USER_CODE(EG(current_execute_data)->func->type)) {
+ const zend_op *opline = EG(current_execute_data)->opline;
+ if (opline && opline->opcode == ZEND_INCLUDE_OR_EVAL &&
+ (opline->extended_value & (ZEND_INCLUDE | ZEND_INCLUDE_ONCE | ZEND_REQUIRE | ZEND_REQUIRE_ONCE))) {
+ size_t filename_len = strlen(filename);
+ size_t phar_len = sizeof(".phar") - 1;
+ if (filename_len > phar_len && memcmp(filename + filename_len - phar_len, ".phar", phar_len) == 0) {
+ open_for_include = 1;
+ }
+ }
+ }
+ /* OPEN_FOR_INCLUDE must be blocking */
+ if (open_for_include) {
+ php_stream *stream = _php_stream_fopen(filename, mode, opened_path, options STREAMS_REL_CC);
+ if (stream != NULL) {
+ stream->ops = &swow_php_stream_stdio_ops;
+ }
+ return stream;
}
+
char realpath[MAXPATHLEN];
int open_flags;
int fd;
