-
Notifications
You must be signed in to change notification settings - Fork 50
/
autoload.php
52 lines (43 loc) · 1.21 KB
/
autoload.php
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* This file is part of the php-resque package.
*
* (c) Michael Haynes <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Autoload file for php-resque speedtest feature.
*/
use Monolog\Handler\StreamHandler;
use Resque\Event;
use Resque\Logger;
use Resque\Resque;
// Test job class
class TestJob
{
public function perform($args): void
{
// Don't do anything
}
}
$logger = new Logger([new StreamHandler('php://stdout')]);
// Lets record the forking time
Event::listen([Event::WORKER_FORK, Event::WORKER_FORK_CHILD], function ($event, $job) use ($logger): void {
static $start = 0;
if ($event === Event::WORKER_FORK_CHILD) {
$exec = microtime(true) - $start;
$logger->log('Forking process took '.round($exec * 1000, 2).'ms', Logger::DEBUG);
} else {
$start = microtime(true);
}
});
// When the job is about to be run, queue another one
Event::listen(Event::JOB_PERFORM, function ($event, $job) use ($logger): void {
Resque::push('TestJob');
});
// Add a few jobs to the default queue
for ($i = 0; $i < 10; $i++) {
Resque::push('TestJob');
}