php clear_queue.php --address=127.0.0.1 --port=4730
Created
October 5, 2016 12:06
-
-
Save omerucel/500a021aa295c8b0665f373d7cb84fa6 to your computer and use it in GitHub Desktop.
Clean gearmand job queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cmdOptions = getopt('', ['address::', 'port::']); | |
$address = $cmdOptions['address']; | |
$port = $cmdOptions['port']; | |
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
socket_connect($socket, $address, $port); | |
$command = 'status' . PHP_EOL; | |
socket_write($socket, $command, strlen($command)); | |
$out = socket_read($socket, 2048); | |
$items = explode("\n", substr($out, 0, strlen($out) - 2)); | |
foreach ($items as $item) { | |
$item = explode("\t", $item); | |
if (count($item) != 4) { | |
continue; | |
} | |
if ($item[1] == 0) { | |
continue; | |
} | |
$jobCount = intval($item[1] - $item[2]); | |
if ($jobCount > 0) { | |
$command = 'gearman -n -h ' . $address . ' -p ' . $port . ' -w -f ' . $item[0] | |
. ' -c ' . $jobCount . ' > /dev/null'; | |
exec('gearman -n -h ' . $address . ' -p ' . $port . ' -w -f ' . $item[0] . ' -c ' . $jobCount . ' > /dev/null'); | |
} | |
} | |
socket_close($socket); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment