sudo apt install libphp-embed
Cargo.toml
[package]
name = "php_embed_min"
version = "0.1.0"
edition = "2021"
[dependencies]
ext-php-rs = { version = "0.15", features = ["embed"] }src/main.rs
use ext_php_rs::embed::Embed;
fn main() {
let result = Embed::run(|| {
// script.php の中の echo/print は(環境によっては)そのまま標準出力へ出ます
Embed::run_script("script.php")?;
Ok::<(), ext_php_rs::embed::EmbedError>(())
});
if let Err(e) = result {
eprintln!("PHP script failed: {e:?}");
}
}
script.php
<?php
echo "printing something...\n";
return 42;