| Crates.io | whynot |
| lib.rs | whynot |
| version | 0.1.1 |
| created_at | 2025-12-17 18:48:55.871009+00 |
| updated_at | 2025-12-17 23:56:07.450103+00 |
| description | Rust β PHP bridge: call PHP functions from Rust, capture return values, output, and exceptions. |
| homepage | https://github.com/nia-cloud-official/whynot |
| repository | https://github.com/nia-cloud-official/whynot |
| max_upload_size | |
| id | 1990953 |
| size | 35,066 |
Rust β PHP bridge that lets you call PHP functions directly from Rust, capture return values, printed output, and exceptions β with async support via threads or Tokio.
PhpException)include and eval supportcall_async_with_cfg)--features async_tokio)To install you can run:
cargo add whynot
Or add to your Cargo.toml:
[dependencies]
whynot = "0.1.1"
php) available in PATHphp/runner.php and php/bootstrap.php) initialized in your projectAfter installing the crate, install the CLI binary:
cargo install whynot
Then run:
whynot-init
This will create a php/ folder in your project root with:
runner.php β the bridge script used internally by whyNotbootstrap.php β where you define your own PHP functions/classesEdit bootstrap.php to add your PHP logic. The Rust side will call into these functions.
use whynot::{new_runtime, PhpRuntime, RuntimeConfig, RuntimeKind};
fn main() {
let cfg = RuntimeConfig::default();
let mut rt = new_runtime(RuntimeKind::Process(cfg)).unwrap();
let result = rt.call("add", &[7.into(), 5.into()]).unwrap();
println!("add.result = {:?}", result.result);
println!("add.output = {:?}", result.output);
}
let boom = rt.call("risky", &[]).unwrap();
if let Some(ex) = boom.exception {
println!("Exception: {} ({})", ex.message, ex.class);
println!("Trace: {}", ex.trace);
}
use whynot::process::ProcRuntime;
let h1 = ProcRuntime::call_async_with_cfg(cfg.clone(), "greet".to_string(), vec!["Milton".into()]);
let h2 = ProcRuntime::call_async_with_cfg(cfg.clone(), "add".to_string(), vec![7.into(), 9.into()]);
println!("greet = {:?}", h1.join().unwrap().unwrap().result);
println!("add = {:?}", h2.join().unwrap().unwrap().result);
Enable the feature:
cargo run --example tokio_async --features async_tokio
Example:
#[tokio::main]
async fn main() {
let cfg = RuntimeConfig::default();
let greet = whynot::async_tokio::call_async(cfg.clone(), "greet".to_string(), vec!["Milton".into()])
.await.unwrap();
println!("greet.result = {:?}", greet.result);
}
whynot/
Cargo.toml
src/
lib.rs
value.rs
macros.rs
process.rs
embedded.rs
async_tokio.rs
php/
runner.php
bootstrap.php
examples/
call_any.rs
async_calls.rs
tokio_async.rs
Pull requests welcome. Please open issues for bugs, feature requests, or questions.