|
2 | 2 |
|
3 | 3 | namespace Clue\React\SQLite;
|
4 | 4 |
|
| 5 | +use Clue\React\SQLite\Io\BlockingDatabase; |
5 | 6 | use Clue\React\SQLite\Io\LazyDatabase;
|
6 | 7 | use Clue\React\SQLite\Io\ProcessIoDatabase;
|
7 | 8 | use React\ChildProcess\Process;
|
@@ -46,6 +47,18 @@ class Factory
|
46 | 47 | * $factory = new Clue\React\SQLite\Factory(null, '/usr/bin/php6.0');
|
47 | 48 | * ```
|
48 | 49 | *
|
| 50 | + * Or you may use this parameter to pass an empty PHP binary path which will |
| 51 | + * cause this project to not spawn a PHP child process for any database |
| 52 | + * interactions at all. In this case, using SQLite will block the main |
| 53 | + * process, but continues to provide the exact same async API. This can be |
| 54 | + * useful if concurrent execution is not needed, especially when running |
| 55 | + * behind a traditional web server (non-CLI SAPI). |
| 56 | + * |
| 57 | + * ```php |
| 58 | + * // advanced usage: empty binary path runs blocking SQLite in same process |
| 59 | + * $factory = new Clue\React\SQLite\Factory(null, ''); |
| 60 | + * ``` |
| 61 | + * |
49 | 62 | * @param ?LoopInterface $loop
|
50 | 63 | * @param ?string $binary
|
51 | 64 | */
|
@@ -109,6 +122,17 @@ public function __construct(LoopInterface $loop = null, $binary = null)
|
109 | 122 | public function open($filename, $flags = null)
|
110 | 123 | {
|
111 | 124 | $filename = $this->resolve($filename);
|
| 125 | + |
| 126 | + if ($this->bin === '') { |
| 127 | + try { |
| 128 | + return \React\Promise\resolve(new BlockingDatabase($filename, $flags)); |
| 129 | + } catch (\Exception $e) { |
| 130 | + return \React\Promise\reject(new \RuntimeException($e->getMessage()) ); |
| 131 | + } catch (\Error $e) { |
| 132 | + return \React\Promise\reject(new \RuntimeException($e->getMessage())); |
| 133 | + } |
| 134 | + } |
| 135 | + |
112 | 136 | return $this->useSocket ? $this->openSocketIo($filename, $flags) : $this->openProcessIo($filename, $flags);
|
113 | 137 | }
|
114 | 138 |
|
|
0 commit comments