1
|
|
|
#!/usr/bin/php -f |
2
|
|
|
<?php |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Nexcess.net Turpentine Extension for Magento |
6
|
|
|
* Copyright (C) 2012 Nexcess.net L.L.C. |
7
|
|
|
* |
8
|
|
|
* This program is free software; you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU General Public License as published by |
10
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License along |
19
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
20
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
require_once(dirname($_SERVER['argv'][0]).'/abstract.php'); |
24
|
|
|
|
25
|
|
|
class Turpentine_Shell_Varnishadm extends Mage_Shell_Abstract { |
26
|
|
|
/** |
27
|
|
|
* Get the real cleaned argv |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
protected function _parseArgs() { |
32
|
|
|
$this->_args = array_slice( |
33
|
|
|
array_filter($_SERVER['argv'], |
34
|
|
|
create_function('$e', |
35
|
|
|
'return $e != \'--\';')), |
36
|
|
|
1 ); |
37
|
|
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function _write() { |
41
|
|
|
$args = func_get_args(); |
42
|
|
|
return call_user_func_array('printf', $args); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Run script |
47
|
|
|
* |
48
|
|
|
* @return null |
49
|
|
|
*/ |
50
|
|
|
public function run() { |
51
|
|
|
$command = str_replace('.', '_', $this->_args[0]); |
52
|
|
|
$params = array_slice($this->_args, 1); |
53
|
|
|
foreach (Mage::helper('turpentine/varnish')->getSockets() as $socket) { |
54
|
|
|
$response = call_user_func_array(array($socket, $command), $params); |
55
|
|
|
$this->_write("=== Result from server [%s]: %d ===\n%s\n", |
56
|
|
|
$socket->getConnectionString(), $response['code'], |
57
|
|
|
$response['text']); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the usage string |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function usageHelp() { |
67
|
|
|
return <<<USAGE |
68
|
|
|
Usage: php -f varnishadm.php -- <command> [args] |
69
|
|
|
php -f varnishadm.php -- ban.url /category/product |
70
|
|
|
|
71
|
|
|
Do the 'help' command to see the list of available commands |
72
|
|
|
|
73
|
|
|
USAGE; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$shell = new Turpentine_Shell_Varnishadm(); |
78
|
|
|
$shell->run(); |
79
|
|
|
|