<?php

/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/9/24
 * Time: 16:09
 */
date_default_timezone_set("PRC");
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$timer = new \Jenner\Timer(\Jenner\Timer::UNIT_KB);
$timer->mark("start");
$async = new \Jenner\Http\Async();
for ($i = 0; $i < 20; $i++) {
    $task = \Jenner\Http\Task::createGet("http://www.baidu.com");
    $async->attach($task, "baidu" . $i);
    $task2 = \Jenner\Http\Task::createGet("http://www.sina.com");
    $async->attach($task2, "sina" . $i);
    $task3 = \Jenner\Http\Task::createGet("http://www.qq.com");
    $async->attach($task3, "qq" . $i);
}
$result = $async->execute();
$timer->mark("end");
$timer->printDiffReport();
예제 #2
0
<?php

/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/7/22
 * Time: 10:34
 */
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// init, set the memory size unit
$timer = new \Jenner\Timer(\Jenner\Timer::UNIT_KB);
// mark a
$timer->mark('a');
sleep(2);
// mark b
$timer->mark('b');
sleep(3);
// mark c
$timer->mark('c');
sleep(4);
// mark d
$timer->mark('d');
// print total report
$timer->printReport();
// get total report
$report = $timer->getReport();
// get the report of mark
$a_report = $timer->getReport('a');
print_r($a_report);
// get the diff report between a and b
$timer->printDiffReportByStartAndEnd('a', 'b');
예제 #3
0
if (1) {
    ini_set("display_errors", "On");
    error_reporting(E_ALL);
}
#var_dump($pdo);exit();
// 查询出已经采集到的所有主题链接
$threads = $pdo->query("SELECT id, detail_url,source_id from list limit 60");
$threads = $threads->fetchAll();
$thread_quantity = count($threads);
// 数据库连接
require '/www/html/workerman/html/cl_spider/zreading/vendor/indieteq/indieteq-php-my-sql-pdo-database-class/Db.class.php';
$db = new Db();
// 多进程遍历,进行抓取
$workers = 1;
$timer = new \Jenner\Timer(\Jenner\Timer::UNIT_KB);
$timer->mark('a');
$pids = array();
for ($i = 0; $i < $workers; $i++) {
    $pids[$i] = pcntl_fork();
    // 创建子进程
    switch ($pids[$i]) {
        case -1:
            alert('创建子进程失败:' . $i);
            exit;
        case 0:
            $key_start = $thread_quantity / $workers * $i;
            $key_end = $thread_quantity / $workers * ($i + 1);
            for ($j = $key_start; $j < $key_end; $j++) {
                $url = $threads[$j]['detail_url'];
                $sourceId = $threads[$j]['source_id'];
                $reg = array('title' => array('.entry-header .entry-name', 'text', '-ins'), 'content' => array('.entry-content', 'html', '-div -script'));
<?php

/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/7/23
 * Time: 9:43
 */
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$timer = new \Jenner\Timer(\Jenner\Timer::UNIT_KB);
$timer->mark('start');
for ($i = 0; $i < 10; $i++) {
    $mysql = mysqli_connect('127.0.0.1', 'root', '', 'test', '3306');
    $result = $mysql->query("select * from async");
    $mysql = mysqli_connect('127.0.0.1', 'root', '', 'test', '3306');
    $result2 = $mysql->query("select * from async");
}
$timer->mark("stop");
$timer->printDiffReport();
<?php

/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/7/23
 * Time: 9:37
 */
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$timer = new \Jenner\Timer(\Jenner\Timer::UNIT_KB);
$timer->mark("start");
for ($i = 0; $i < 10; $i++) {
    try {
        $async_mysql = new \Jenner\Mysql\Async();
        $async_mysql->attach(['host' => '127.0.0.1', 'user' => 'root', 'password' => '', 'database' => 'test', 'port' => 3306], 'select ID, NAME from async');
        $async_mysql->attach(['host' => '127.0.0.1', 'user' => 'root', 'password' => '', 'database' => 'test', 'port' => 3306], 'select ID, NAME from async');
        $result = $async_mysql->execute();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
$timer->mark("stop");
$timer->printDiffReport();