Process
- callRoute
- isRunning
- reportOnPid
- getPidFileFolder
- getAmountProcessesMax
- getAmountProcessesRecorded
- getAmountProcessesAvailable
- savePid
- hasPidFile
- deletePidFile
- getRunningPidFileArray
- getZombiePidFileArray
- deleteZombieFiles
- destruct
- Process config
- Process Event Listener
callRoute
calls a Route non-blocking
/** @var int $iPid */
$iPid = Process::callRoute('/404/');- calls a Route non-blocking
- saves the (int) id of the process (the pid) into the pid file folder
- returns the (int) id of the process (the pid)
$iPid  
// type: int
12345Events
- mvc.process.callRoute.before; containing the route- $sRoute
- mvc.process.callRoute.after; containing- array('sRoute' => $sRoute, 'iPid' => $iPid)
isRunning
checks whether a process identified by its process id is running
/** @var boolean $bIsRunning */
$bIsRunning = Process::isRunning(12345);$bIsRunning  
// type: boolean
truereportOnPid
get a report on processes
// default
echo nl2br(
  Process::reportOnPid()
);
// with modified symbols
echo nl2br(
  Process::reportOnPid(
    sRunningSymbol: '<i class="fa fa-gear text-success"></i>',
    sZombieSymbol: '<i class="fa fa-skull-crossbones text-danger"></i>'
  )
);echo output
⚙ Running: 274196 since 2025-01-03 10:03:47
⚙ Running: 274198 since 2025-01-03 10:03:47
⚙ Running: 274200 since 2025-01-03 10:03:47
️️☠️ Zombie: 274202 since 2025-01-03 10:01:00getPidFileFolder
returns the absolute path to the pid file folder
/** @var string $sPidFileFolder */
$sPidFileFolder = Process::getPidFileFolder();$sPidFileFolder  
// type: string
'/var/www/html/application/pid/'getAmountProcessesMax
returns the maximum number of all job processes allowed
/** @var int $iMaxProcesses */
$iMaxProcesses = Process::getAmountProcessesMax();$iMaxProcesses  
// type: integer
30getAmountProcessesRecorded
detect running processes (=== amount of current pidfiles in pid file folder)
/** @var int $iAmount */
$iAmount = Process::getAmountProcessesRecorded();$iAmount
// type: integer
2getAmountProcessesAvailable
returns the amount of available processes
/** @var int $iAmount */
$iAmount = Process::getAmountProcessesAvailable();$iAmount
// type: integer
28savePid
saves pid from getmypid() as a file into the pid file folder
/** @var boolean $bSave */
$bSave = Process::savePid();saves the given pid as a file into the pid file folder
/** @var boolean $bSave */
$bSave = Process::savePid(iPid: 12345);saves the given pid as a file into the pid file folder, plus the pid file contains the argument $mContent JSON encoded
/** @var boolean $bSave */
$bSave = Process::savePid(
    iPid: 12345, 
    mContent: array(
        'foo' => 'bar'
    ) 
);$bSave
// type: boolean
truehasPidFile
checks whether there exists a pid file in the pid file folder relating to the current pid
/** @var boolean $bHasPidFile */
$bHasPidFile = Process::hasPidFile();- if no pid ist given, the current pid from getmypid()is automatically taken
checks whether there exists a pid file in the pid file folder relating to the given pid
/** @var boolean $bHasPidFile */
$bHasPidFile = Process::hasPidFile(12345);$bHasPidFile
// type: boolean
truedeletePidFile
deletes pid file in the pid file folder relating to the current pid
/** @var boolean $bDelete */
$bDelete = Process::deletePidFile();- if no pid ist given, the current pid from getmypid()is automatically taken
deletes pid file in the pid file folder relating to the given pid
/** @var boolean $bDelete */
$bDelete = Process::deletePidFile(12345);$bDelete
// type: boolean
truegetRunningPidFileArray
returns array with absolute path to running pidfiles
/** @var array $aRunning */
$aRunning = Process::getRunningPidFileArray();$aRunning
// type: array, items: 1
[
    0 => '/var/www/html/application/pid/1841',
]getZombiePidFileArray
returns detected real zombies as array containing absolute path to zombie pidfiles
/** @var array $aZombie */
$aZombie = Process::getZombiePidFileArray();$aZombie
// type: array, items: 0
[
]deleteZombieFiles
deletes all zombie pid files
Process::deleteZombieFiles();Event
- mvc.process.deleteZombieFiles.after; containing the deleted pid file- $sPidFile
destruct
this method is called at each event that matches the pattern *.controller.*.__destruct. See Process Event Listener 
deletes pid-files on shutdown
Process::destruct();Event
- mvc.process.destruct.after; containing the process id (the pid) of the ended process in- $iPid
Process config
the queue main config resides in config/_mvc.php. Override to your needs in your module's config files.
config
MVC_PROCESS: {
    // Maximum number of all job processes allowed in parallel
    $aConfig['MVC_PROCESS_MAX_PROCESSES_OVERALL'] = 30;
    // pidFiles directory
    $aConfig['MVC_PROCESS_PID_FILE_DIR'] = $aConfig['MVC_APPLICATION_PATH'] . '/pid/';
}Process Event Listener
modules/Foo/etc/event/process.php  
<?php
\MVC\Event::processBindConfigStack([
    /*
     * Events for which the process destructor should be called
     * '*.controller.*.__destruct',
     */
    '*.__destruct' => [
        function() {
            \MVC\Process::destruct();
        }
    ],
    'mvc.process.callRoute.before' => [
        function (string $sRoute) {
//            \MVC\Log::write($sRoute, \MVC\Config::get_MVC_LOG_FILE_PROCESS());
        },
    ],
    'mvc.process.callRoute.after' => [
        function (array $aInfo) {
            \MVC\Log::write(json_encode($aInfo), \MVC\Config::get_MVC_LOG_FILE_PROCESS());
        },
    ],
    'mvc.process.deleteZombieFiles.after' => [
        function (string $sPidFile) {
            \MVC\Log::write('pidfile: ' . $sPidFile . "\tDELETE ZOMBIE", \MVC\Config::get_MVC_LOG_FILE_PROCESS());
        },
    ],
    'mvc.process.destruct.after' => [
        function (int $iPid) {
            \MVC\Log::write('pid: ' . $iPid . "\tDELETE", \MVC\Config::get_MVC_LOG_FILE_PROCESS());
        },
    ],
]); Emvicy
        Emvicy
    
    