2017-07-21 21:15:43 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Service\Forking;
|
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
|
|
|
|
class Driver implements \JKingWeb\Arsse\Service\Driver {
|
|
|
|
protected $queue = [];
|
|
|
|
|
|
|
|
static function driverName(): string {
|
|
|
|
return Arsse::$lang->msg("Driver.Service.Forking.Name");
|
|
|
|
}
|
|
|
|
|
|
|
|
static function requirementsMet(): bool {
|
|
|
|
return function_exists("popen");
|
|
|
|
}
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function queue(int ...$feeds): int {
|
|
|
|
$this->queue = array_merge($this->queue, $feeds);
|
|
|
|
return sizeof($this->queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exec(): int {
|
|
|
|
$pp = [];
|
|
|
|
while($this->queue) {
|
|
|
|
$id = (int) array_shift($this->queue);
|
2017-07-22 19:29:12 +00:00
|
|
|
$php = '"'.\PHP_BINARY.'"';
|
|
|
|
$arsse = '"'.$_SERVER['argv'][0].'"';
|
|
|
|
array_push($pp, popen("$php $arsse feed refresh $id", "r"));
|
2017-07-21 21:15:43 +00:00
|
|
|
}
|
|
|
|
while($pp) {
|
|
|
|
$p = array_pop($pp);
|
|
|
|
fgets($p); // TODO: log output
|
|
|
|
pclose($p);
|
|
|
|
}
|
|
|
|
return Arsse::$conf->serviceQueueWidth - sizeof($this->queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
function clean(): bool {
|
|
|
|
$this->queue = [];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|