aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-27 05:11:32 +0900
committernsfisis <nsfisis@gmail.com>2026-06-27 05:11:51 +0900
commitf87b930a5bf21d2f60a53151599e0953b7c1f99e (patch)
tree617b5e94d7d4384727da6826c632d8695e9facb7 /crates
parent6d53dd16759df8b2cde09047ddcf460652034fd9 (diff)
downloadphp-shirabe-f87b930a5bf21d2f60a53151599e0953b7c1f99e.tar.gz
php-shirabe-f87b930a5bf21d2f60a53151599e0953b7c1f99e.tar.zst
php-shirabe-f87b930a5bf21d2f60a53151599e0953b7c1f99e.zip
feat(php-shim): drop shutdown function shim, defer OOM message to PHP
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-php-shim/src/runtime.rs20
-rw-r--r--crates/shirabe/src/console/application.rs34
-rw-r--r--crates/shirabe/src/main.rs3
3 files changed, 11 insertions, 46 deletions
diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs
index e002138..88ab7ae 100644
--- a/crates/shirabe-php-shim/src/runtime.rs
+++ b/crates/shirabe-php-shim/src/runtime.rs
@@ -529,24 +529,6 @@ pub fn ini_set(_varname: &str, _value: &str) -> Option<String> {
todo!()
}
-thread_local! {
- static SHUTDOWN_FUNCTIONS: std::cell::RefCell<Vec<Box<dyn Fn()>>> =
- const { std::cell::RefCell::new(Vec::new()) };
-}
-
-pub fn register_shutdown_function(callback: Box<dyn Fn()>) {
- SHUTDOWN_FUNCTIONS.with(|f| f.borrow_mut().push(callback));
-}
-
-// Runs the registered shutdown functions in registration order, mirroring PHP
-// executing them at the end of the request. Must be invoked at every process exit.
-pub fn run_shutdown_functions() {
- let functions = SHUTDOWN_FUNCTIONS.with(|f| std::mem::take(&mut *f.borrow_mut()));
- for callback in &functions {
- callback();
- }
-}
-
pub fn composer_dev_warning_time() -> i64 {
// TODO(phase-d): COMPOSER_DEV_WARNING_TIME is a build-time constant baked into Composer's release
// artifact; it has no fixed value in source and must be provided by the build process.
@@ -590,8 +572,6 @@ pub fn phpinfo(_what: i64) {
}
pub fn exit(status: i64) -> ! {
- // PHP runs registered shutdown functions before terminating.
- run_shutdown_functions();
std::process::exit(status as i32);
}
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index d34a736..de1ecfc 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -45,12 +45,12 @@ use shirabe_external_packages::symfony::process::exception::ProcessTimedOutExcep
use shirabe_php_shim::{
LogicException as ShimLogicException, PHP_BINARY, PHP_VERSION, PHP_VERSION_ID, PhpMixed,
RuntimeException, bin2hex, chdir, date_default_timezone_get, date_default_timezone_set,
- defined, dirname, disk_free_space, error_get_last, extension_loaded, file_exists,
- file_get_contents, file_put_contents, function_exists, getcwd, getmypid, glob, in_array,
- ini_set, is_array, is_dir, is_file, is_string, is_subclass_of, json_decode,
- memory_get_peak_usage, memory_get_usage, microtime, php_uname, posix_getuid, random_bytes,
- realpath, register_shutdown_function, restore_error_handler, round, str_contains, str_replace,
- strpos, strtoupper, sys_get_temp_dir, time, unlink,
+ defined, dirname, disk_free_space, extension_loaded, file_exists, file_get_contents,
+ file_put_contents, function_exists, getcwd, getmypid, glob, in_array, ini_set, is_array,
+ is_dir, is_file, is_string, is_subclass_of, json_decode, memory_get_peak_usage,
+ memory_get_usage, microtime, php_uname, posix_getuid, random_bytes, realpath,
+ restore_error_handler, round, str_contains, str_replace, strpos, strtoupper, sys_get_temp_dir,
+ time, unlink,
};
use crate::command::AboutCommand;
@@ -148,7 +148,6 @@ impl Application {
"#;
pub fn new(name: String, mut version: String) -> Self {
- static SHUTDOWN_REGISTERED: std::sync::OnceLock<()> = std::sync::OnceLock::new();
if version.is_empty() {
version = composer::get_version();
}
@@ -167,23 +166,10 @@ impl Application {
let io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> =
std::rc::Rc::new(std::cell::RefCell::new(NullIO::new()));
- SHUTDOWN_REGISTERED.get_or_init(|| {
- register_shutdown_function(Box::new(|| {
- let last_error = error_get_last();
-
- let message = last_error
- .as_ref()
- .and_then(|m| m.get("message"))
- .and_then(|v| v.as_string())
- .unwrap_or("");
- if !message.is_empty()
- && (strpos(message, "Allowed memory").is_some()
- || strpos(message, "exceeded memory").is_some())
- {
- println!("\nCheck https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.");
- }
- }));
- });
+ // TODO(phase-d): Composer registers shutdown function that reports special message for
+ // OOM. In Shirabe, limit of memory allocation has effect only on PHP side so that the
+ // corresponding shutdown function should be registered in PHP runtime, not here.
+ // if (!$shutdownRegistered) { ... }
let initial_working_directory = getcwd();
diff --git a/crates/shirabe/src/main.rs b/crates/shirabe/src/main.rs
index 538d89d..e3cb963 100644
--- a/crates/shirabe/src/main.rs
+++ b/crates/shirabe/src/main.rs
@@ -1,6 +1,6 @@
//! ref: composer/bin/composer
-use shirabe_php_shim::{PHP_ENV, PHP_SERVER, run_shutdown_functions};
+use shirabe_php_shim::{PHP_ENV, PHP_SERVER};
fn main() {
// Take the $_ENV / $_SERVER snapshots before any putenv() mutates the real environment.
@@ -9,7 +9,6 @@ fn main() {
std::sync::LazyLock::force(&PHP_SERVER);
let result = shirabe::run(std::env::args().collect());
- run_shutdown_functions();
let mut exit_code = match result {
Ok(exit_code) => exit_code,
Err(e) => {