aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon/Cache_query.php
blob: 18d19cdf29452840c11f184c1bbd341f5e5ff6ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

namespace Zotlabs\Daemon;

use Zotlabs\Lib\Cache;

class Cache_query {

	static public function run($argc, $argv) {

		if(! $argc == 3)
			return;

		$key = $argv[1];

		$pid = get_config('procid', $key, false);
		if ($pid && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) {
			logger($key . ': procedure already run with pid ' . $pid, LOGGER_DEBUG);
			return;
		}

		$pid = getmypid();
		set_config('procid', $key, $pid);

		array_shift($argv);
		array_shift($argv);

		$r = call_user_func_array('q', $argv);
		if($r)
			Cache::set($key, serialize($r));

		del_config('procid', $key);
	}
}