php-phantomjs中文API整理的集合DEMO

安装:

首先要安装composer

安装composer中文镜像http://www.phpcomposer.com/,然后重启

创建composer.json

{
        "scripts": {
            "post-install-cmd": [
                "PhantomInstaller\\Installer::installPhantomJS"
            ],
            "post-update-cmd": [
                "PhantomInstaller\\Installer::installPhantomJS"
            ]
        },
        "config": {
            "bin-dir": "bin"
        },
        "require": {
                "jonnyw/php-phantomjs": "4.*"
        }
}

然后安装

进入项目文件夹运行下面的的命令即可 composer require “jonnyw/php-phantomjs:4.*”

运行测试代码

getEngine()->setPath('E:/xampp/php/phantomjs.exe');
    //上面一行要填写自己的phantomjs路径
    /** 
     * @see JonnyW\PhantomJs\Http\PdfRequest
     **/
    delay = 7;request = client->getMessageFactory()->createPdfRequest('https://www.baidu.com/', 'GET', 5000); //参数里面的数字5000是网页加载的超时时间,放在网络问题一直加载,可以不填写,默认5s。request->setOutputFile('E:/document.pdf');
    request->setFormat('A4');request->setOrientation('landscape');
    request->setMargin('1cm');request->setDelay(delay);//设置delay是因为有一些特效会在页面加载完成后加载,没有等待就会漏掉

    /**     * @see JonnyW\PhantomJs\Http\Response     **/response = client->getMessageFactory()->createResponse();

    // Send the requestclient->send(request,response);

demo说明:

浏览全部

centos 安装 PhantomJS

  1. 安装步骤

1.1 在服务器上新建想要下载和安装的目录:

如mkdir  PhantomJS

1.2 下载PhantomJS安装包

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

 

 

执行结果如下图:

1.3 解压工具包

tar -xjvf phantomjs-2.1.1-linux-x86_64.tar.bz2

 

执行时报如下错误:

tar (child): cannot run bzip2: No such file or directory

出现上述错误,请安装bzip2

执行指令:

 

yum -y install bzip2

 

再次执行解压指令:

成功完成解压。

1.4 将可执行文件放入系统路径

sudo ln -s ~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

 

1.5 安装依赖——fontconfig和freetype:

yum install fontconfig
 
yum install freetype
 

1.6 在终端下测试Phantomjs

注意系统目录为/usr/bin/ 至此成功

centos 安装 php-v8js

Centos 安装v8js

yum install php-pear

yum install re2c

yum install v8-devel

pecl install v8js-0.1.3 // if failed, need to download v8js-0.1.3 and manually install it

// modify b8js.cc and add the blow info line 1

#define PHP_V8_VERSION “0.1.3”

phpize ./configure –with-v8js make make test make install

echo “extension=v8js.so” >> /etc/php.ini

ubuntu 安装 php-v8js扩展

直接pecl install v8js……报错。。

root@ubuntu:/usr/local/src/v8js-1.3.5# ./configure --with-php-config=/usr/local/php7/bin/php-config 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php7
checking for PHP includes... -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303
checking for PHP installed headers prefix... /usr/local/php7/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.13.5 (ok)
checking for gawk... gawk
checking for V8 javascript Engine... yes, shared
checking for V8 files in default path... found in /usr
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for C standard version... c++11
checking how to allow c++11 narrowing... 
checking for libv8_libplatform... checking for libv8_libplatform... configure: error: could not find libv8_libplatform library

 

系统自带的libv8版本太低了。

sudo add-apt-repository ppa:pinepain/libv8
sudo apt-get update

 

卸載原先的libv8-dev,執行apt-get install libv8-6.6-dev

nice

Build process completed successfully
Installing '/usr/lib/php5/20121212/v8js.so'
install ok: channel://pecl.php.net/v8js-0.6.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=v8js.so" to php.ini

 

Centos 清理日志文件

使用CentOS系统的时候,经常会遇到系统日志文件非常大的情况,如果直接删除,会导致日志错误,不再生成日志,这时,我们可以使用下面的方法清空日志。

  • [Centos6]
  • [Centos7]

    CentOS 6系统

    cat /dev/null > /var/log/boot.log
    cat /dev/null > /var/log/btmp
    cat /dev/null > /var/log/cron
    cat /dev/null > /var/log/dmesg
    cat /dev/null > /var/log/dracut.log
    cat /dev/null > /var/log/lastlog
    cat /dev/null > /var/log/maillog
    cat /dev/null > /var/log/messages
    cat /dev/null > /var/log/secure
    cat /dev/null > /var/log/spooler
    cat /dev/null > /var/log/tallylog
    cat /dev/null > /var/log/wtmp
    cat /dev/null > /var/log/yum.log

    CentOS 7系统

    cat /dev/null > /var/log/boot.log
    cat /dev/null > /var/log/btmp
    cat /dev/null > /var/log/cron
    cat /dev/null > /var/log/dmesg
    cat /dev/null > /var/log/firewalld
    cat /dev/null > /var/log/grubby
    cat /dev/null > /var/log/lastlog
    cat /dev/null > /var/log/mail.info
    cat /dev/null > /var/log/maillog
    cat /dev/null > /var/log/messages
    cat /dev/null > /var/log/secure
    cat /dev/null > /var/log/spooler
    cat /dev/null > /var/log/syslog
    cat /dev/null > /var/log/tallylog
    cat /dev/null > /var/log/wpa_supplicant.log
    cat /dev/null > /var/log/wtmp
    cat /dev/null > /var/log/yum.log