jakoch/phantomjs-installer
Composer 安装命令:
composer require jakoch/phantomjs-installer
包简介
A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into `/bin` of your project.
关键字:
README 文档
README
A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into /bin of your project.
Table of Contents
Installation
To install PhantomJS as a local, per-project dependency to your project, simply add a dependency on jakoch/phantomjs-installer to your project's composer.json file.
{
"require": {
"jakoch/phantomjs-installer": "^3"
},
"config": {
"bin-dir": "bin"
},
"scripts": {
"post-install-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
],
"post-update-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
]
}
}
For a development dependency, change require to require-dev.
The default download source used is: https://bitbucket.org/ariya/phantomjs/downloads/ You might change it by setting a custom CDN URL, which is explained in the section "Downloading from a mirror".
By setting the Composer configuration directive bin-dir, the vendor binaries will be installed into the defined folder.
Important! Composer will install the binaries into vendor\bin by default.
The scripts section is necessary, because currently Composer does not pass events to the handler scripts of dependencies. If you leave it away, you might execute the installer manually.
Now, assuming that the scripts section is set up as required, the PhantomJS binary
will be installed into the /bin folder and updated alongside the project's Composer dependencies.
How to require specific versions of PhantomJS?
The environment and server variable PHANTOMJS_VERSION enables you specify the version requirement at the time of packaging.
You can also set the phantomjs-version in the extra section of your composer.json:
"extra": { "jakoch/phantomjs-installer": { "phantomjs-version": "2.1.1" } }
The search order for the version is 1) $_ENV, 2) $_SERVER, 3) composer.json (extra section), 4) fallback to v2.1.1 (hardcoded latest version).
How does this work internally?
- Fetching the PhantomJS Installer
In your composer.json you require the package "phantomjs-installer".
The package is fetched by composer and stored into ./vendor/jakoch/phantomjs-installer.
It contains only one file the PhantomInstaller\\Installer.
- Platform-specific download of PhantomJS
The PhantomInstaller\\Installer is run as a "post-install-cmd". That's why you need the "scripts" section in your "composer.json".
The installer creates a new composer in-memory package "phantomjs",
detects your OS and downloads the correct Phantom version to the folder ./vendor/jakoch/phantomjs.
All PhantomJS files reside there, especially the examples.
- Installation into
/binfolder
The binary is then copied from ./vendor/jakoch/phantomjs to your composer configured bin-dir folder.
- Generation of PhantomBinary
The installer generates a PHP file PhantomInstaller\\PhantomBinary and inserts the path to the binary.
PhantomBinary
To access the binary and its folder easily, the class PhantomBinary is created automatically during installation.
The class defines the constants BIN and DIR:
BINis the full-path to the PhantomJS binary file, e.g./your_project/bin/phantomjsDIRis the folder of the binary, e.g./your_project/bin
Both constants are also accessible via their getter-methods getBin() and getDir().
Usage:
use PhantomInstaller\PhantomBinary;
// get values with class constants
$bin = PhantomInstaller\PhantomBinary::BIN;
$dir = PhantomInstaller\PhantomBinary::DIR;
// get values with static functions
$bin = PhantomInstaller\PhantomBinary::getBin();
$dir = PhantomInstaller\PhantomBinary::getDir();
This feature is similar to location.js of the phantomjs module for Node.
Override platform requirements
The environment and server variables PHANTOMJS_PLATFORM and PHANTOMJS_BITSIZE enable you to
override the platform requirements at the time of packaging. This decouples the packaging system
from the target system. It allows to package on Linux for MacOSX or on Windows for Linux.
Possible values for
PHANTOMJS_PLATFORMare:macosx,windows,linux.PHANTOMJS_BITSIZEare:32or64.
Downloading from a mirror
You can override the default download location of the PhantomJS binary file by setting it in one of these locations. Listed in order of precedence (highest first):
- The environment variable
PHANTOMJS_CDNURL - The server variable
PHANTOMJS_CDNURL - In your
composer.jsonby using$['extra']['jakoch/phantomjs-installer']['cdnurl']:
"extra": { "jakoch/phantomjs-installer": { "cdnurl": "https://github.com/Medium/phantomjs/releases/download/v1.9.19/" } },
Default Download Location
The default download location is Bitbucket: https://api.bitbucket.org/2.0/repositories/ariya/phantomjs/downloads/.
You don't need to set it explicitly. It's used, when PHANTOMJS_CDNURL is not set.
Mirrors
You might use one of the following mirror URLs as a value for PHANTOMJS_CDNURL:
https://cnpmjs.org/downloads/- USAhttps://npm.taobao.org/mirrors/phantomjs/- Chinahttps://github.com/Medium/phantomjs/- USAhttps://repo1.maven.org/maven2/com/github/klieber/phantomjs/- USAhttps://mirrors.huaweicloud.com/phantomjs/- China
This list of mirrors is not complete. If you know another mirror, please don't hesitate to add it here.
The mirror URLs are also not hardcoded, except for the Github URL.
This enables you to point to any PhantomJS mirror or download folder you like.
For instance, you could point to the URL of the download folder of your company, where the binaries are stored:
PHANTOMJS_CDNURL=https://cdn.company.com/downloads/phantomjs/.
Automatic download retrying with version lowering on 404
In case downloading an archive fails with HttpStatusCode 404 (resource not found),
the downloader will automatically lower the version to the next available version
and retry. The number of retries is determined by the number of hardcoded PhantomJS
versions in getPhantomJSVersions(). This feature was added, because of the problems
with v2.0.0 not being available for all platforms (see issue #25).
jakoch/phantomjs-installer 适用场景与选型建议
jakoch/phantomjs-installer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.45M 次下载、GitHub Stars 达 151, 最近一次更新时间为 2013 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「headless」 「phantomjs」 「binaries」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jakoch/phantomjs-installer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jakoch/phantomjs-installer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jakoch/phantomjs-installer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HTML to PDF Symfony bundle. Works with Puppeteer, PhantomJS, and more.
PhantomJS client for SERPS
This extension provides integration with solr to output content from TYPO3 in JSON format.
Instrument headless chrome/chromium instances from php5.6
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
PHP Automation Tools
统计信息
- 总下载量: 5.45M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 158
- 点击次数: 28
- 依赖项目数: 81
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2013-08-03