Story Details

  • Using uv as your shebang line

    Posted: 2025-01-28 17:35:05

    The blog post explores using #!/usr/bin/env uv as a shebang line to execute PHP scripts with the uv runner, offering a performance boost compared to traditional PHP execution methods like php-fpm. uv leverages libuv for asynchronous operations, making it particularly advantageous for I/O-bound tasks. The author demonstrates this by creating a simple "Hello, world!" script and showcasing the performance difference using wrk. The post concludes that while setting up uv might require some initial effort, the potential performance gains, especially in asynchronous contexts, make it a compelling alternative for running PHP scripts.

    Summary of Comments ( 94 )
    https://news.ycombinator.com/item?id=42855258

    Hacker News users discussed the practicality and security implications of using uv as a shebang line. Some questioned the benefit given the small size savings compared to a full path, while others highlighted potential portability issues and the risk of uv not being installed on target systems. A compelling argument against this practice centered on security, with commenters noting the danger of path manipulation if uv isn't found and the shell falls back to searching the current directory. One commenter suggested using env to locate usr/bin/env reliably, proposing #!/usr/bin/env uv as a safer, though slightly larger, alternative. The overall sentiment leaned towards avoiding this shortcut due to the potential downsides outweighing the minimal space saved.