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