PHP Warning: proc_open(): CreateProcess failed, error code - 267

Sam Wilson picture Sam Wilson · May 18, 2015 · Viewed 8k times · Source

A proc_open call like the following is failing with the above error.

<?php
$proc = proc_open($cmd, $ds, $pipes, '/tmp', array());

The command $cmd works correctly when executed directly.

Answer

Sam Wilson picture Sam Wilson · May 18, 2015

The problem has nothing to do with the actual command being executed.

Error code 267 is ERROR_DIRECTORY "The directory name is invalid." and in this case simply means that the /tmp directory doesn't exist on the drive that the code is being run from.

Instead of /tmp, use sys_get_temp_dir() (which one can assume will always exist).