2017-07-21 21:15:43 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-07-21 21:15:43 +00:00
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2019-01-21 03:40:49 +00:00
|
|
|
namespace JKingWeb\Arsse\Service\Subprocess;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-07-21 21:15:43 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
|
|
|
|
class Driver implements \JKingWeb\Arsse\Service\Driver {
|
|
|
|
protected $queue = [];
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public static function driverName(): string {
|
2019-01-21 03:40:49 +00:00
|
|
|
return Arsse::$lang->msg("Driver.Service.Subprocess.Name");
|
2017-07-21 21:15:43 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public static function requirementsMet(): bool {
|
2017-07-21 21:15:43 +00:00
|
|
|
return function_exists("popen");
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function __construct() {
|
2017-07-21 21:15:43 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function queue(int ...$feeds): int {
|
2017-07-21 21:15:43 +00:00
|
|
|
$this->queue = array_merge($this->queue, $feeds);
|
|
|
|
return sizeof($this->queue);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function exec(): int {
|
2017-07-21 21:15:43 +00:00
|
|
|
$pp = [];
|
2017-08-29 14:50:31 +00:00
|
|
|
while ($this->queue) {
|
2017-07-21 21:15:43 +00:00
|
|
|
$id = (int) array_shift($this->queue);
|
2019-01-23 14:32:44 +00:00
|
|
|
$php = escapeshellarg(\PHP_BINARY);
|
|
|
|
$arsse = escapeshellarg($_SERVER['argv'][0]);
|
2019-10-19 22:51:01 +00:00
|
|
|
array_push($pp, $this->execCmd("$php $arsse feed refresh $id"));
|
2017-07-21 21:15:43 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
while ($pp) {
|
2017-07-21 21:15:43 +00:00
|
|
|
$p = array_pop($pp);
|
|
|
|
fgets($p); // TODO: log output
|
|
|
|
pclose($p);
|
|
|
|
}
|
|
|
|
return Arsse::$conf->serviceQueueWidth - sizeof($this->queue);
|
|
|
|
}
|
|
|
|
|
2019-10-19 22:51:01 +00:00
|
|
|
/** @codeCoverageIgnore */
|
|
|
|
protected function execCmd(string $cmd) {
|
|
|
|
return popen($cmd, "r");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clean(): int {
|
|
|
|
$out = sizeof($this->queue);
|
2017-07-21 21:15:43 +00:00
|
|
|
$this->queue = [];
|
2019-10-19 22:51:01 +00:00
|
|
|
return $out;
|
2017-07-21 21:15:43 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|