PHP code example of mvccore / ext-tool-cli-winfork

1. Go to this page and download the library: Download mvccore/ext-tool-cli-winfork library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mvccore / ext-tool-cli-winfork example snippets




// standard web request process:

cCore\Application::GetInstance();
$req = $app->GetRequest();
$indexScriptAbsPath = $req->GetDocumentRoot() . $req->GetScriptName();
$phpParams = "-d max_execution_time=0 -d memory_limit=-1";
$bgProcessParams = "controller=bg-process action=calculate";
$cliDirFullPath = $app->GetPathCli(TRUE);

// prepare bg command:
$cmd = "php {$phpParams} {$indexScriptAbsPath} {$bgProcessParams}";
if (substr(mb_strtolower(PHP_OS), 0, 3) === 'win') {
	// Fork.exe automatically finds php.exe, php.bat or php.cmd in %PATH%
	$cmd = "Fork.exe {$cmd}";
} else {
	// Unix system needs to has php executable in $PATH environment variable
	// for user running web request scripts (eg: www, apache):
	$cmd = 'bash -c "exec nohup setsid ' . $cmd . ' > /dev/null 2>&1 &"';
}

// start second bg process:
$cwdBefore = getcwd();
chdir($cliDirFullPath);
system($cmd);
chdir($cwdBefore);

// continue in the standard web request process without 
// waiting for the background process execution end...