Closed azurre closed 2 years ago
The problem:
php test.phar
PHP Fatal error: Uncaught RuntimeException: Unable to launch a new process: proc_open(): CreateProcess failed, error code - 267
Achieve wanted:
Exapmle:
<?php
use Clue\React\SQLite\Factory;
(function() {
// --- additional part for phar application ---
$options = getopt('', ['sqlite::']);
if (isset($options['sqlite'])) { // Run worker
if (isset($_SERVER['argv'][2])) { // Handle Windows
$_SERVER['argv'][1] = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : $_SERVER['argv'][1];
} else {
unset($_SERVER['argv'][1]); // Handle *nix
}
return include __DIR__ . '/vendor/clue/reactphp-sqlite/res/sqlite-worker.php';
}
$worker = $cwd = null;
if (strpos(__DIR__, 'phar://') === 0) {
$app = Phar::running(false);
$worker = "{$app} --sqlite=1";
$cwd = dirname($app);
}
// -------------------------------------------
require_once __DIR__ . '/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop, $worker, $cwd);
$db = $factory->openLazy('users.db');
$db->exec('CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, bar STRING)');
$name = 'Alice';
$db->query('INSERT INTO foo (bar) VALUES (?)', [$name])->then(
function(Clue\React\SQLite\Result $result) use ($name) {
echo 'New ID for ' . $name . ': ' . $result->insertId . PHP_EOL;
}
);
$db->quit();
$loop->run();
})();
As a result
$ php test.phar
New ID for Alice: 8
and
$ php test.php
New ID for Alice: 9
works as expected on windows & *nix
Hi @clue
I've updated my previous comment
I'm closing this for now as it hasn't received any input in a while and I believe this is best addressed with #5 in a future version. If you feel this is still relevant, please come back with more details and we can always reopen this :+1:
Thank you for your effort, keep it up! :+1:
Fix make able use reactphp-sqlite with phar applications + fix filename regexp (windows path support)