Guzzle can do this out of the box! This technique is also used to power some of the checks in Oh Dear.
PHP
Understanding Traceroute
A clear walkthrough of how traceroute works under the hood. It explains the TTL trick, the ICMP replies routers send back, and even rebuilds the core idea in Rust. Read more