-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_execution.rs
More file actions
31 lines (22 loc) · 818 Bytes
/
basic_execution.rs
File metadata and controls
31 lines (22 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Basic PHP script execution demonstrating simple GET request handling.
//!
//! Run: `cargo run --example basic_execution`
use std::path::PathBuf;
use ripht_php_sapi::{RiphtSapi, WebRequest};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let sapi = RiphtSapi::instance();
let script_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/php_scripts")
.join("hello.php");
let exec = WebRequest::get().build(&script_path)?;
let result = sapi.execute(exec)?;
println!("Body: {}", result.body_string());
println!("Status: {}", result.status_code());
if result.has_errors() {
eprintln!("PHP errors occurred:");
for error in result.errors() {
eprintln!(" {:?}: {}", error.level, error.message);
}
}
Ok(())
}