@@ 78-94 (lines=17) @@ | ||
75 | * @param int $size |
|
76 | * @return string |
|
77 | */ |
|
78 | public function read($size = 1024) |
|
79 | { |
|
80 | if (!is_resource($this->read)) { |
|
81 | $this->read = fopen($this->filename, 'r+'); |
|
82 | if (!is_resource($this->read)) { |
|
83 | throw new \RuntimeException('open file failed'); |
|
84 | } |
|
85 | if (!$this->block) { |
|
86 | $set = stream_set_blocking($this->read, false); |
|
87 | if (!$set) { |
|
88 | throw new \RuntimeException('stream_set_blocking failed'); |
|
89 | } |
|
90 | } |
|
91 | } |
|
92 | ||
93 | return fread($this->read, $size); |
|
94 | } |
|
95 | ||
96 | /** |
|
97 | * @param $message |
|
@@ 100-116 (lines=17) @@ | ||
97 | * @param $message |
|
98 | * @return int |
|
99 | */ |
|
100 | public function write($message) |
|
101 | { |
|
102 | if (!is_resource($this->write)) { |
|
103 | $this->write = fopen($this->filename, 'w+'); |
|
104 | if (!is_resource($this->write)) { |
|
105 | throw new \RuntimeException('open file failed'); |
|
106 | } |
|
107 | if (!$this->block) { |
|
108 | $set = stream_set_blocking($this->write, false); |
|
109 | if (!$set) { |
|
110 | throw new \RuntimeException('stream_set_blocking failed'); |
|
111 | } |
|
112 | } |
|
113 | } |
|
114 | ||
115 | return fwrite($this->write, $message); |
|
116 | } |
|
117 | ||
118 | /** |
|
119 | * |