Month: July 2024

php: concurrency with processes. pt. 1: using pcntl_fork for fun and performance

i often joke that php is a systems programming language that you can also use to create a home page. it’s not really true, of course; no one is going to write, say, a video driver in php. but it does highlight the fact that php has an absolute tonne of functionality that is either straight through calls to c or built-in libraries that allow us to access all sorts of operating systems features.

in this series, we’re going to leverage some of that power to write a php program that does multiple things at the same time. we’ll do that by using pcntl_fork to create a number of child processes that run simultaneously. then in part two, we’ll be looking at shmop, php’s ‘shared memory operations’, as a way to allow those processes to communicate their results.

a process forking a copy of itself to do work concurrently
Continue reading →

amber: writing bash scripts in amber instead. pt. 4: functions

a while ago, i blogged about uploading files to s3 using curl and provided the solution as two functions written in bash, and basically the only feedback was “wait. you can write functions in bash?”

you can. but in reality, you probably don’t want to. the syntax for defining (and calling) bash functions is horrible. there’s a reason people genrally don’t use them. writing and using functions in amber, by comparison, is a borderline delight of sanity. if you’ve ever written a function in php or python or javascript, amber’s function syntax will feel familiar and, well, ‘normal’.

a look at the syntax of functions in bash
Continue reading →