jakoch/phantomjs-installer
Laravel-friendly installer for PhantomJS. Downloads and installs the PhantomJS binary via Composer with cross-platform support, making it easy to bundle a headless browser in PHP apps and CI pipelines without manual setup.
/bin directory, avoiding system-wide conflicts and ensuring consistency across environments (dev/staging/prod).spatie/pdf-to-text or laravel-headless-chrome for broader automation needs, though PhantomJS is deprecated in favor of modern alternatives (e.g., Puppeteer, Playwright). Risk: Long-term maintainability if PhantomJS support is dropped.require jakoch/phantomjs-installer in composer.json. Automatically handles OS-specific binaries (Linux, macOS, Windows).// config/app.php
'providers' => [
// ...
App\Providers\PhantomJsServiceProvider::class,
],
$_ENV['PATH'] or getenv('PATH') for subprocess calls (e.g., exec('phantomjs script.js')). Requires explicit path resolution in Laravel’s config or environment files.puppeteer/puppeteer) in README and deprecation warnings./bin path be exposed to Laravel’s subprocess calls (e.g., exec(), Process facade)?php artisan screenshots:generate).GeneratePdfJob).$this->app->singleton('phantomjs.path', function () {
return base_path('/bin/phantomjs');
});
composer require jakoch/phantomjs-installer
post-install-cmd to composer.json to verify installation:
"scripts": {
"post-install-cmd": [
"@php bin/phantomjs --version"
]
}
exec() calls with resolved path:
$path = base_path('/bin/phantomjs');
exec("$path script.js");
class PhantomJsService {
public function __construct(private string $path) {}
public function render(string $script): string {
return shell_exec("{$this->path} {$script}");
}
}
exec() in unit tests (e.g., using Mockery).exec() calls with:
// Example: Using Symfony Process (bundled with Laravel)
use Symfony\Component\Process\Process;
$process = new Process(['/path/to/puppeteer', 'script.js']);
$process->run();
jakoch/phantomjs-installer for updates (though risk of breaking changes is low).CONTRIBUTING.md or UPGRADE.md for:
which phantomjs (Linux/macOS) or where phantomjs (Windows).phantomjs: command not found (common if path isn’t in $PATH)./bin is writable by the PHP process (e.g., chmod +x /bin/phantomjs).libfontconfig (Linux). Document in README.| Issue | Owner | SLA |
|---|---|---|
| Binary installation | Package author | Best effort |
| Laravel integration | TPM | 24h |
| PhantomJS crashes | TPM | 48h |
k6 or Laravel Dusk to measure memory/CPU impact.| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| PhantomJS binary missing | Task failures | Pre-flight checks in bootstrap/app.php. |
| PhantomJS crashes (segfault) | Silent failures | Implement health checks (e.g., ping endpoint). |
| High memory usage | OOM kills | Set memory limits (e.g., ulimit -v 1024). |
| OS incompatibility | Deployment failures | Dockerize with multi-stage builds. |
| Deprecation of PhantomJS | Technical debt | Plan 6-month migration to Puppeteer. |
/bin path resolution and basic usage (e.g., exec() examples).How can I help you explore Laravel packages today?