-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Magento 2.4.4, PHP 8.1, Ubuntu 22.04
- Loading branch information
1 parent
e30bfcf
commit b6f0b5a
Showing
39 changed files
with
1,336 additions
and
285 deletions.
There are no files selected for viewing
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
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
55 changes: 55 additions & 0 deletions
55
magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/ServerAddress.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
|
||
namespace PAJ\Library\Docker\Scale\Varnish\Admin; | ||
|
||
class ServerAddress | ||
{ | ||
const DEFAULT_HOST = '127.0.0.1'; | ||
const DEFAULT_PORT = 6082; | ||
/** | ||
* Host on which varnishadm is listening. | ||
* | ||
* @var string | ||
*/ | ||
private $host; | ||
/** | ||
* Port on which varnishadm is listening, usually 6082. | ||
* | ||
* @var int port | ||
*/ | ||
private $port; | ||
|
||
/** | ||
* ServerAddress constructor. | ||
* @param string $host | ||
* @param int $port | ||
*/ | ||
public function __construct($host, $port) | ||
{ | ||
$this->host = $host; | ||
if (empty($this->host)) { | ||
$this->host = self::DEFAULT_HOST; | ||
} | ||
$this->port = $port; | ||
if (empty($this->port)) { | ||
$this->port = self::DEFAULT_PORT; | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getHost() | ||
{ | ||
return $this->host; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getPort() | ||
{ | ||
return $this->port; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/Socket.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
|
||
namespace PAJ\Library\Docker\Scale\Varnish\Admin; | ||
|
||
use \Exception; | ||
|
||
class Socket | ||
{ | ||
private $fp; | ||
|
||
private $host; | ||
private $port; | ||
|
||
public function openSocket($host, $port, $timeout) | ||
{ | ||
|
||
$this->host = $host; | ||
$this->port = $port; | ||
$errno = null; | ||
$errstr = null; | ||
|
||
$this->fp = fsockopen($this->host, $this->port, $errno, $errstr, $timeout); | ||
if (!is_resource($this->fp)) { | ||
// error would have been raised already by fsockopen | ||
throw new Exception(sprintf( | ||
'Failed to connect to varnishadm on %s:%s; "%s"', | ||
$this->host, | ||
$this->port, | ||
$errstr | ||
)); | ||
} | ||
// set socket options | ||
stream_set_blocking($this->fp, 1); | ||
stream_set_timeout($this->fp, $timeout); | ||
} | ||
|
||
public function read(&$code) | ||
{ | ||
$code = null; | ||
$len = null; | ||
// get bytes until we have either a response code and message length or an end of file | ||
// code should be on first line, so we should get it in one chunk | ||
while (!feof($this->fp)) { | ||
$response = fgets($this->fp, 1024); | ||
if (!$response) { | ||
$meta = stream_get_meta_data($this->fp); | ||
if ($meta['timed_out']) { | ||
throw new Exception(sprintf('Timed out reading from socket %s:%s', $this->host, $this->port)); | ||
} | ||
} | ||
if (preg_match('/^(\d{3}) (\d+)/', $response, $r)) { | ||
$code = (int)$r[1]; | ||
$len = (int)$r[2]; | ||
break; | ||
} | ||
} | ||
if (is_null($code)) { | ||
throw new Exception('Failed to get numeric code in response'); | ||
} | ||
$response = ''; | ||
while (!feof($this->fp) && strlen($response) < $len) { | ||
$response .= fgets($this->fp, 1024); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
|
||
public function write($data) | ||
{ | ||
$bytes = fputs($this->fp, $data); | ||
if ($bytes !== strlen($data)) { | ||
throw new Exception(sprintf('Failed to write to varnishadm on %s:%s', $this->host, $this->port)); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function close() | ||
{ | ||
is_resource($this->fp) && fclose($this->fp); | ||
$this->fp = null; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdmin.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* Varnish admin socket for executing varnishadm CLI commands. | ||
* | ||
* @see https://www.varnish-cache.org/docs/4.0/reference/varnish-cli.html | ||
* | ||
* @author Jesus Lopez http://jesuslc.com | ||
**/ | ||
|
||
namespace PAJ\Library\Docker\Scale\Varnish\Admin; | ||
|
||
interface VarnishAdmin | ||
{ | ||
/** | ||
* Brutal close, doesn't send quit command to varnishadm. | ||
*/ | ||
public function close(); | ||
|
||
/** | ||
* Connect to admin socket. | ||
* | ||
* @param int $timeout in seconds, defaults to 5; used for connect and reads | ||
* | ||
* @return string the banner, in case you're interested | ||
*/ | ||
public function connect($timeout = 5); | ||
|
||
/** | ||
* Shortcut to purge function. | ||
* | ||
* @see https://www.varnish-cache.org/docs/4.0/users-guide/purging.html | ||
* | ||
* @param string $expr is a purge expression in form "<field> <operator> <arg> [&& <field> <oper> <arg>]..." | ||
* | ||
* @return string | ||
*/ | ||
public function purge($expr); | ||
|
||
/** | ||
* Shortcut to purge.url function. | ||
* | ||
* @see https://www.varnish-cache.org/docs/4.0/users-guide/purging.html | ||
* | ||
* @param string $url is a url to purge | ||
* | ||
* @return string | ||
*/ | ||
public function purgeUrl($url); | ||
|
||
/** | ||
* Graceful close, sends quit command. | ||
*/ | ||
public function quit(); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function start(); | ||
|
||
/** | ||
* Test varnish child status. | ||
* | ||
* @return bool whether child is alive | ||
*/ | ||
public function status(); | ||
|
||
/** | ||
* Set authentication secret. | ||
* Warning: may require a trailing newline if passed to varnishadm from a text file. | ||
* | ||
* @param string | ||
*/ | ||
public function setSecret($secret); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function stop(); | ||
} |
Oops, something went wrong.