Skip to content

Instantly share code, notes, and snippets.

@yarimadam
Created May 22, 2018 07:47
Show Gist options
  • Save yarimadam/24f0d033709478d8b4038bdd2f05f0c3 to your computer and use it in GitHub Desktop.
Save yarimadam/24f0d033709478d8b4038bdd2f05f0c3 to your computer and use it in GitHub Desktop.
Run php script in background with symfony process component
<?php
require 'vendor/autoload.php';
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
$builder = new ProcessBuilder();
$builder->setPrefix('/usr/local/bin/php');
$cmd = $builder->setArguments(['/Users/tuncay/longRunningTask.php'])
->getProcess()
->getCommandLine();
$process = new Process($cmd . ' > /dev/null 2>&1 &');
$process->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment