Skip to content

Instantly share code, notes, and snippets.

@matthieuprat
Last active December 15, 2015 12:19
Show Gist options
  • Save matthieuprat/422df4b8be3f488570ad to your computer and use it in GitHub Desktop.
Save matthieuprat/422df4b8be3f488570ad to your computer and use it in GitHub Desktop.
PHP's recursive mkdir() is not thread-safe
$ cd $(mktemp -d) && echo -n 1:2 | xargs -d: -n1 -P2 php --no-php-ini -r 'mkdir(str_repeat("dir/", 100) . $argv[1], 0777, true) or exit(1);' && echo OK
Warning: mkdir(): File exists in Command line code on line 1
$ cd $(mktemp -d) && echo -n 1:2 | xargs -d: -n1 -P2 php --no-php-ini -r 'system(sprintf("mkdir -p %s", str_repeat("dir/", 100) . $argv[1]), $r); exit($r);' && echo OK
OK
$ cd $(mktemp -d) && echo -n 1:2 | xargs -d: -n1 -P2 python -c 'import os, sys; os.makedirs('dir/' * 100 + sys.argv[1]);' && echo 'OK'
OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment