@@ -56,19 +56,25 @@ const LibraryExample = {
56
56
57
57
// The files from the preload directory are preloaded using the
58
58
// auto_prepend_file php.ini directive.
59
- FS . mkdir ( '/internal/shared/preload' ) ;
59
+ FS . mkdirTree ( '/internal/shared/preload' ) ;
60
60
// Platform-level bin directory for a fallback `php` binary. Without it,
61
61
// PHP may not populate the PHP_BINARY constant.
62
- FS . mkdir ( '/internal/shared/bin' ) ;
62
+ FS . mkdirTree ( '/internal/shared/bin' ) ;
63
63
const originalOnRuntimeInitialized = Module [ 'onRuntimeInitialized' ] ;
64
64
Module [ 'onRuntimeInitialized' ] = ( ) => {
65
- // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
66
- FS . writeFile (
65
+ const { node : phpBinaryNode } = FS . lookupPath (
67
66
'/internal/shared/bin/php' ,
68
- new TextEncoder ( ) . encode ( '#!/bin/sh\nphp "$@"' )
67
+ { noent_okay : true } ,
69
68
) ;
70
- // It must be executable to be used by PHP.
71
- FS . chmod ( '/internal/shared/bin/php' , 0o755 ) ;
69
+ if ( ! phpBinaryNode ) {
70
+ // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
71
+ FS . writeFile (
72
+ '/internal/shared/bin/php' ,
73
+ new TextEncoder ( ) . encode ( '#!/bin/sh\nphp "$@"' )
74
+ ) ;
75
+ // It must be executable to be used by PHP.
76
+ FS . chmod ( '/internal/shared/bin/php' , 0o755 ) ;
77
+ }
72
78
originalOnRuntimeInitialized ( ) ;
73
79
} ;
74
80
0 commit comments