PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.18.8
JetBackup – Backup, Restore & Migrate v3.1.18.8
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / 3rdparty / SocketAPI / Socket / Socket.php
backup / src / JetBackup / 3rdparty / SocketAPI / Socket Last commit date
.htaccess 5 months ago Socket.php 5 months ago index.html 5 months ago web.config 5 months ago
Socket.php
87 lines
1 <?php
2 /*
3 *
4 * JetBackup @ package
5 * Created By Idan Ben-Ezra
6 *
7 * Copyrights @ JetApps
8 * https://www.jetapps.com
9 *
10 **/
11 namespace JetBackup\SocketAPI\Socket;
12
13 use JetBackup\SocketAPI\Exception\SocketException;
14 use JetBackup\SocketAPI\Message\MessageReader;
15 use JetBackup\SocketAPI\Message\MessageWriter;
16
17 class Socket {
18
19 private $_socket;
20 private $_stream;
21 private $_file;
22
23 private $_reader;
24 private $_writer;
25
26 /**
27 * Socket constructor.
28 * @param $socket
29 * @throws SocketException
30 */
31 public function __construct($socket=null) {
32 $this->_socket = $socket ?: socket_create(AF_UNIX, SOCK_STREAM, 0);
33 if(!$this->getSocketResource()) throw new SocketException("Could not create socket");
34 }
35
36 /**
37 * @param string $file
38 */
39 public function setFile($file) { $this->_file = $file; }
40
41 /**
42 * @return string
43 */
44 public function getFile() { return $this->_file; }
45
46 public function getSocketResource() { return $this->_socket; }
47 public function getStreamResource() {
48 if(!$this->_stream) $this->_stream = socket_export_stream($this->getSocketResource());
49 return $this->_stream;
50 }
51
52
53 /**
54 * @return MessageReader
55 */
56 public function getReader(): MessageReader {
57 if(!$this->_reader) $this->_reader = new MessageReader($this);
58 return $this->_reader;
59 }
60
61 /**
62 * @return MessageWriter
63 */
64 public function getWriter(): MessageWriter {
65 if(!$this->_writer) $this->_writer = new MessageWriter($this);
66 return $this->_writer;
67 }
68
69 /**
70 * @param bool $isServer
71 *
72 * @throws SocketException
73 */
74 public function connect( bool $isServer=false) {
75 if(!$this->getFile()) throw new SocketException("There is no socket file set");
76 if($isServer && file_exists($this->getFile())) @unlink($this->getFile());
77 if (!file_exists($this->getFile()) || !is_readable($this->getFile())) throw new SocketException("Could not connect to socket (not exist).");
78 if(!@socket_connect($this->getSocketResource(), $this->getFile())) throw new SocketException("Could not connect to socket (socket error).");
79 }
80
81 /**
82 *
83 */
84 public function close() {
85 @socket_close($this->getSocketResource());
86 }
87 }