exec() with timeout

I’ve searched a bit on this topic and came to conclusion that in some case (if you are using linux) you can use ‘timeout’ command. It’s pretty flexible Usage: timeout [OPTION] DURATION COMMAND [ARG]… or: timeout [OPTION] in my particular case I’m trying to run sphinx indexer from PHP, kinda migration data script so I … Read more

Pipes, dup2 and exec()

You need to close all the pipe descriptors in both the parent process and the child process (after duplication in the child process). In your code the main issue is that, the wc process does not exit because there are still writers present (since the parent process has not closed the write end). Changes shown … Read more

Can’t execute PHP script using PHP exec

I had this issue also and it turns out this is a bug in php (#11430). The fix is to use php-cli when calling another php script within a php script. So you can still use exec but rather than use php use php-cli when calling it in the browser: exec(“php-cli somescript.php”); This worked for … Read more

Windows CMD.exe “The system cannot find the path specified.”

The problem is that some program has been set to autorun when you run cmd.exe. In my case it was ANSICON that was installed… and then I moved the file without properly uninstalling. I found a solution in this blog post: http://carol-nichols.com/2011/03/17/the-system-cannot-find-the-path-specified/ The short version is to find HKCU\Software\Microsoft\Command Processor\AutoRun and clear the value.

Running python script in Laravel

Use Symfony Process. https://symfony.com/doc/current/components/process.html Install: composer require symfony/process Code: use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; $process = new Process([‘python’, ‘/path/to/your_script.py’]); $process->run(); // executes after the command finishes if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } echo $process->getOutput();

Faster forking of large processes on Linux?

On Linux, you can use posix_spawn(2) with the POSIX_SPAWN_USEVFORK flag to avoid the overhead of copying page tables when forking from a large process. See Minimizing Memory Usage for Creating Application Subprocesses for a good summary of posix_spawn(2), its advantages and some examples. To take advantage of vfork(2), make sure you #define _GNU_SOURCE before #include … Read more