Esempio n. 1
0
function first()
{
    var_dump(__FUNCTION__ . ' - ' . 1);
    yield from delay(1000);
    var_dump(__FUNCTION__ . ' - ' . 2);
    yield from delay(1000);
    yield from second();
    return 5;
}
Esempio n. 2
0
function bogomips()
{
    // Please consider using http://pecl.php.net/package/hrtime
    // Wall clock is susceptible to changes in OS date/time, eg. NTP induced
    for ($loops = 1; $loops > 0; $loops <<= 1) {
        $start = time();
        delay($loops);
        $end = time() - $start;
        if ($end > 1) {
            $bogomips = $loops / $end / 500000;
            return sprintf('%0.2f', $bogomips);
        }
    }
    return;
}
function x($CCTLD, $lng, $runDepth, $keyword, $operator)
{
    global $message, $pattern, $stack;
    $queryUrl = 'http://www.google.' . $CCTLD . '/search?q=' . urlencode('' . $keyword . ' "' . $operator . '"') . '&hl=' . $lng . '&start=' . $runDepth . '&pws=0' . '\\n';
    //$queryUrl= 'http://www.google.'.$CCTLD.'/search?q='.urlencode($keyword).'&hl='.$lng.'&start='.$runDepth.'&pws=0'.'\n';
    //echo $queryUrl."\n";
    echo 'Query: ' . $keyword . ' "' . $operator . '" - Start ' . $runDepth . "\n";
    $html = file_get_contents($queryUrl);
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $x = new DOMXPath($dom);
    $i = 1;
    foreach ($x->query("//div[@id='ires']//h3//a") as $node) {
        delay();
        $url = $node->getAttribute('href');
        $url = trim($url, "/url?q=");
        $url = current(explode('&sa', $url));
        array_push($stack, $url);
        //echo $url."\n";
        $i++;
    }
}
Esempio n. 4
0
<?php

//引入提醒模块公共函数
require "foundation/module_remind.php";
require "foundation/fdelay.php";
//数据表定义区
$t_online = $tablePreStr . "online";
$DELAY_ONLINE = 4;
//更新当前用户时间
$is_action = delay($DELAY_ONLINE);
if ($is_action) {
    $dbo = new dbex();
    dbtarget('w', $dbServs);
    update_online_time($dbo, $t_online);
    rewrite_delay();
}
function mainExecute()
{
    //support variables for logic
    $matches = [];
    $alt_dom = '';
    $i = 0;
    $memeIDCounter = 1;
    $page_count = 50;
    $csvFileName = 'mogmaster.csv';
    $toCSV = true;
    //array for offline pages testing
    // $offlinePages = ['staticpages/Slender Man _ Know Your Meme.html','staticpages/Forever Alone _ Know Your Meme.html', 'staticpages/Zerg Rush _ Know Your Meme.html'];
    //Regexes for matching values from extractions
    $rgx_src = '/data-src="(.*)" src/';
    //image url
    $rgx_title = '/title="(.*)"/';
    //Meme title
    $rgx_pg_href = '/href="(.*)">/';
    //url for meme's page
    $rgx_faves = '/>(.*)</';
    //favorites count
    $rgx_views = '/>(.*)</';
    //View count
    $rgx_origin = '/>(.*)</';
    //Origin
    $rgx_org_year = '';
    $rgx_nsfw = '/>NSFW</';
    //utility variables specifying desired Dom content selectors for extractContent function
    $meme_img_path = '.entry_list .photo img';
    $meme_url_path = '.entry_list h2 > a';
    $meme_faves_path = '.num';
    $meme_views_path = 'dd.views a';
    $meme_origin_path = 'dd.entry_origin_link';
    $meme_nsfw_path = 'span.label-nsfw';
    //Variables to store scraped content
    $meme_name = '';
    $meme_img_url = '';
    // $meme_localPath = '';
    $meme_faves = null;
    $meme_views = null;
    $meme_origin = null;
    $meme_year = null;
    $meme_learn_more = '';
    //Recreate CSV file
    createCSV($csvFileName);
    //main work loop
    while ($i <= $page_count) {
        //counter for tracking meme url index in $meme_href
        $j = 0;
        //counter used for offline pages array index
        // $m = 0;
        //pull and store scraped dom
        $html = getDOM('http://knowyourmeme.com/memes/popular/page/' . ($i + 1));
        delay();
        //These arrays should refer to the same memes on the same indexes
        //extracts array used for meme images and titles
        $img_content = extractContent($html, $meme_img_path);
        //extracts array used for meme url to access additional content
        $meme_href = extractContent($html, $meme_url_path);
        foreach ($img_content as $curr) {
            //check if meme is NSFW
            $meme_nsfw = extractContent($curr, $meme_nsfw_path);
            if (!empty($meme_nsfw)) {
                $active = 0;
            } else {
                $active = 1;
            }
            echo "Meme NSFW: {$active}" . PHP_EOL;
            // //save meme name
            $meme_name = getValue($curr, $rgx_title, false, '');
            preg_match($rgx_title, $curr, $matches);
            $meme_name = $matches[1];
            echo "Meme Name: " . $meme_name . PHP_EOL;
            //save meme img url
            $meme_img_url = getValue($curr, $rgx_src, false, '');
            preg_match($rgx_src, $curr, $matches);
            $meme_img_url = $matches[1];
            echo "Meme IMG URL: " . $meme_img_url . PHP_EOL;
            //get href for current meme in $curr and set variable
            preg_match($rgx_pg_href, $meme_href[$j], $matches);
            $meme_learn_more = "http://knowyourmeme.com" . $matches[1];
            echo "Meme Main URL: " . $meme_learn_more . PHP_EOL;
            //Get DOM for current selected meme to scrape additional content
            //for offline testing
            $alt_dom = getDOM("http://knowyourmeme.com" . $matches[1]);
            delay();
            // $alt_dom = getDOM($offlinePages[$m]);
            //extract favorite count
            $meme_faves = getValue($alt_dom, $rgx_faves, true, $meme_faves_path);
            $fave_segment = extractContent($alt_dom, $meme_faves_path);
            preg_match($rgx_faves, $fave_segment[0], $matches);
            $meme_faves = $matches[1];
            echo "Meme Favorite Count: " . $meme_faves . PHP_EOL;
            //extract view count
            $view_segment = extractContent($alt_dom, $meme_views_path);
            preg_match($rgx_views, $view_segment[0], $matches);
            $meme_views = $matches[1];
            echo "Meme Views: " . $meme_views . PHP_EOL;
            //Save image file to local path and collect path for saving
            saveImg($meme_img_url, $memeIDCounter);
            $memeIDCounter++;
            // //extract meme origin
            // $origin_segment = extractContent($alt_dom, $meme_origin_path);
            // preg_match($rgx_origin, $origin_segment[0], $matches);
            // $meme_origin = $matches[1];
            // echo "Meme Origin: " . $meme_origin . "<br>";
            echo PHP_EOL;
            //create Mog object and call save method
            $mog = new Mog($meme_name, $meme_img_url, $meme_views, $meme_faves, $meme_learn_more, $active);
            if ($toCSV) {
                $mog->saveToCSV($csvFileName);
            } else {
                $mog->saveToDB();
            }
            echo "Total Memes Scraped: {$memeIDCounter}" . PHP_EOL;
            // $m++;
            $j++;
        }
        echo 'Page ' . ($i + 1) . 'Done...' . PHP_EOL;
        echo PHP_EOL;
        $i++;
        sleep(rand(15, 60));
    }
    echo "all pages done!" . PHP_EOL;
}
Esempio n. 6
0
use function jubianchi\async\runtime\{await, all, fork, race};
use function jubianchi\async\time\{delay};
use jubianchi\async\socket;
$address = '0.0.0.0';
$port = $_SERVER['argv'][1] ?? 1337;
$queue = [];
$start = function ($socket, $address, $port) use(&$queue) {
    socket_bind($socket, $address, $port);
    socket_listen($socket, 0);
    socket_set_nonblock($socket);
    $index = 0;
    $cancel = false;
    while ($cancel == false) {
        $client = socket_accept($socket);
        if ($client) {
            echo '> Got client...' . PHP_EOL;
            $queue[] = (function () use($index, $client, $address, $port) {
                echo '> Handling request #' . $index . '...' . PHP_EOL;
                $response = 'Hello World!';
                $output = 'HTTP/1.1 200 OK' . "\r\n" . 'Date: ' . date("D, j M Y G:i:s T") . "\r\n" . 'Server: AsyncGenerator/1.0.0 (PHP ' . phpversion() . ')' . "\r\n" . 'Content-Length: ' . strlen($response) . "\r\n" . 'Content-Type: text/plain' . "\r\n" . "\r\n" . $response . "\r\n";
                yield from delay(1000);
                yield from socket\write($client, $output, 5);
                socket_close($client);
            })();
            echo '> Client request #' . $index++ . ' queued...' . PHP_EOL;
        }
        $cancel = yield;
    }
    socket_close($socket);
};
await(race($start(socket_create(AF_INET, SOCK_STREAM, 0), $address, $port), fork($queue)));
Esempio n. 7
0
    $start = microtime(true);
    $out = $workerState->cache->safeNonBlocking('value', null, function () {
        delay();
        return 'set value';
    }, $result);
    return [$result, $start, microtime(true)];
}, 'check' => $bits['ensureNonOverlappingSet']], 'lockerUnsafeNonBlocking' => ['setupParent' => function () {
    apc_clear_cache('user');
}, 'setupWorker' => function ($workerState) use($bits) {
    $cache = $bits['createFileLockerCache']($workerState);
    $workerState->cache->backend->useBackendExpirations = false;
}, 'test' => function ($workerState) {
    $cache = $workerState->cache;
    $start = microtime(true);
    $setter = function () {
        delay();
        return 'set value';
    };
    $out = $workerState->cache->unsafeNonBlocking('value', null, $setter, $found, $result);
    $ret = [$result, $start, microtime(true)];
    // 10000 is the locker key. this is brittle.
    $cache->locker->acquire($cache, 10000);
    $cache->locker->release($cache, 10000);
    $out = $workerState->cache->get('value');
    $ret[] = $out;
    return $ret;
}, 'check' => function ($workers, $responses, $parentState) use($bits) {
    $result = $bits['ensureNonOverlappingSet']($workers, $responses, $parentState);
    if (!$result[0]) {
        return $result;
    }
Esempio n. 8
0
<?php

/*
 * This file is part of the async generator runtime project.
 *
 * (c) Julien Bianchi <*****@*****.**>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */
require_once __DIR__ . '/../vendor/autoload.php';
use function jubianchi\async\runtime\{await, race};
use function jubianchi\async\time\{delay, throttle};
$start = microtime(true);
await(race(delay(3000), throttle(500, function () {
    var_dump(__LINE__);
}), throttle(1000, function () {
    var_dump(__LINE__);
})));
echo 'Time spent: ' . ($with = microtime(true) - $start) . PHP_EOL;
Esempio n. 9
0
<?php

//index.php
require_once __DIR__ . '/../../vendor/autoload.php';
use function jubianchi\async\runtime\{await, all};
use function jubianchi\async\time\{delay};
$start = microtime(true);
await(all(delay(5000, function () {
    echo 'World!';
}), delay(2000, function () {
    echo 'Hello';
})));
echo PHP_EOL . 'Time spent: ' . ($with = microtime(true) - $start) . PHP_EOL;
Esempio n. 10
0
<?php

/**
 * Copyright (c) 2008 Massachusetts Institute of Technology
 * 
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 */
require_once "ShuttleSchedule.php";
$schedule = new ShuttleSchedule();
$schedule->route("Cambridge East", "saferidecambeast", "SafeRide")->summary("Runs every evening, all year round")->perHour(2)->stops(st("84 Mass. Ave", "mass84_d", "frcamp", '00'), st("NW10 / Edgerton", "nw10", "frcamp", '03'), st("NW30 / Warehouse", "nw30", "frcamp", '04'), st("NW86 / 70 Pacific", "nw86", "frcamp", '05'), st("NW61 / Random Hall", "nw61", "frcamp", '06'), st("Main St @ Windsor St", "mainwinds", "frcamp", '09'), st("Portland St @ Hampshire St", "porthamp", "frcamp", '10'), st("638 Cambridge St", "camb638", "frcamp", '13'), st("Cambridge St @ Fifth St", "camb5th", "frcamp", '14'), st("Sixth @ Charles St", "6thcharl", "tocamp", '15'), st("East Lot on Main St", "elotmain", "tocamp", '17'), st("Bld 66 (Ames St)", "amesbld66", "tocamp", '18'), st("MIT Medical / 34 Carleton", "mitmed", "tocamp", '20'), st("Kendall T", "kendsq", "tocamp", '22'), st("E40 / Wadsworth", "wadse40", "tocamp", '23'), st("77 Mass. Ave", "mass77", "tocamp", '26'))->addHours("Thu-Sat", hours("18-22")->append(delay(5, "23 0 1 2 3:1")))->addHours("Sun-Wed", hours("18-21")->append(delay(5, "22 23 0 1 2:1")));
$schedule->route("Cambridge West", "saferidecambwest", "SafeRide")->summary("Runs every evening, all year round")->perHour(2)->stops(st("84 Mass. Ave", "mass84_d", "frcamp", '00'), st("W4 / McCormick", "mccrmk", "frcamp", '01'), st("W51 / Burton", "burtho", "frcamp", '02'), st("W70 / New House", "newho", "frcamp", '03'), st("W85 / Tang / Westgate", "tangwest", "frcamp", '04'), st("W79 / Simmons", "simmhl", "frcamp", '06'), st("WW15 (Request)", "ww15", "frcamp", '07'), st("Brookline St @ Chestnut St", "brookchest", "frcamp", '09'), st("Putnum Ave @ Magazine St", "putmag", "frcamp", '10'), st("River St @ Fairmont St", "rivfair", "frcamp", '12'), st("River St @ Upton St", "rivpleas", "frcamp", '13'), st("River St @ Franklin St", "rivfrank", "tocamp", '14'), st("Sydney @ Green St", "sydgreen", "tocamp", '16'), st("NW86 / 70 Pacific St", "paci70", "tocamp", '18'), st("NW30 / Warehouse", "whou", "tocamp", '19'), st("NW10 / Edgerton", "edge", "tocamp", '20'))->addHours("Thu-Sat", hours("18-22")->append(delay(5, "23 0 1 2 3:1")))->addHours("Sun-Wed", hours("18-21")->append(delay(5, "22 23 0 1 2:1")));
$schedule->route("Boston West", "saferidebostonw", "SafeRide")->summary("Runs every evening, all year round")->perHour(2)->stops(st("84 Mass Ave", "mass84_d", "boston", '15'), st("Mass Ave @ Beacon St", "massbeac", "boston", '18'), st("528 Beacon St", "beac528", "boston", '19'), st("487 Comm Ave", "comm487", "boston", '21'), st("64 Baystate", "bays64", "boston", '23'), st("111 Baystate", "bays111", "boston", '24'), st("155 Baystate", "bays155", "boston", '25'), st("259 St Paul St (ET)", "stpaul259", "boston", '32'), st("58 Manchester (ZBT)", "manc58", "mass84", '34'), st("550 Memorial Drive", "memo550", "mass84", '40'), st("Simmons Hall", "simmhl", "mass84", '41'))->addHours("Thu-Sat", hours("18-22")->append(delay(5, "23 0 1 2 3:1")))->addHours("Sun-Wed", hours("18-21")->append(delay(5, "22 23 0 1 2:1")));
$schedule->route("Boston East", "saferidebostone", "SafeRide")->summary("Runs every evening, all year round")->perHour(2)->stops(st("84 Mass. Ave", "mass84_d", "boston", '00'), st("Mass. Ave / Beacon St", "massbeac", "boston", '02'), st("478 Comm. Ave", "comm478", "boston", '04'), st("Vanderbilt (Request)", NULL, NULL, '06'), st("28 Fenway", "fenw28", "boston", '10'), st("Prudential Center", "prud", "boston", '12'), st("229 Comm Ave", "comm229", "boston", '15'), st("253 Comm Ave", "comm253", "mass84", '16'), st("32 Hereford St", "here32", "mass84", '17'), st("450 Beacon St", "beac450", "mass84", '18'), st("Beacon St @ Mass. Ave", "beacmass", "mass84", '19'))->addHours("Thu-Sat", hours("18-22")->append(delay(5, "23 0 1 2 3:1")))->addHours("Sun-Wed", hours("18-21")->append(delay(5, "22 23 0 1 2:1")));
$schedule->route("Tech Shuttle", "tech")->summary("Runs weekdays 7AM-6PM, all year round")->except_holidays()->perHour(3)->stops(st("Kendall Square T", "kendsq_d", "wcamp", '15'), st("Amherst/Wadsworth", "amhewads", "wcamp", '17'), st("Media Lab", "medilb", "wcamp", '18'), st("Building 39", "build39", "wcamp", '20'), st("84 Mass Avenue", "mass84", "wcamp", '22'), st("Burton House", "burtho", "wcamp", '24'), st("Audrey Street", "tangwest", "wcamp", '26'), st("Simmons Hall", "simmhl", "kendsq", '27'), st("Vassar/Mass Ave", "vassmass", "kendsq", '29'), st("Stata", "statct", "kendsq", '30'))->addHours("Mon-Fri", hours("7-18"), delay(30, "7-9"), delay(-10, "16-17"));
$schedule->route("Northwest Shuttle", "northwest")->summary("Runs weekdays 7AM-6PM, all year round")->except_holidays()->perHour(3)->stops(st("Kendall Square T", "kendsq_d", "nwcamp", '25'), st("Amherst/Wadsworth", "amhewads", "nwcamp", '27'), st("77 Mass Avenue", "mass77", "nwcamp", '30'), st("MIT Museum (N52)", "mitmus", "nwcamp", '32'), st("70 Pacific Street (NW86)", "paci70", "kendsq", '34'), st("The Warehouse (NW30)", "whou", "kendsq", '35'), st("Edgarton (NW10)", "edge", "kendsq", '36'), st("Vassar/Mass Ave", "vassmass", "kendsq", '39'), st("Stata", "statct", "kendsq", '41'))->addHours("Mon-Fri", hours("7-17 18:1"), delay(10, "7-9"));
$schedule->route("Boston Daytime", "boston")->summary("Runs weekdays 8AM-6PM, Sep-May")->except_holidays()->perHour(3)->stops(st("84 Mass. Ave.", "mass84_d", "boston", '07'), st("Mass. Ave. / Beacon", "massbeac", "cambridge", '09'), st("487 Comm. Ave. (PSK)", "comm487", "cambridge", '10'), st("64 Bay State (TXI)", "bays64", "cambridge", '11'), st("478 Comm. Ave.", "comm478", "cambridge", '14'), st("450 Beacon St.", "beac450", "cambridge", '19'), st("77 Mass. Ave.", "mass77", "cambridge", '23'))->addHours("Mon-Fri", hours("8-17"));
Esempio n. 11
0
 static function delay($howLong)
 {
     delay($howLong);
 }
Esempio n. 12
0
function test_2($ip, $port, $name, $t, $char)
{
    $t = 1000;
    $value = "11";
    $name = "0001";
    echo "------test 2 --------\n";
    maxqueue($ip, $port, $name, "maxqueue", 1000000000, $t, "200");
    delay($ip, $port, $name, "delay", 2, $t, "200");
    put($ip, $port, $name, "hello", $t, "200");
    put($ip, $port, $name, "hello", $t, "200");
    put($ip, $port, $name, "hello", $t, "200");
    put($ip, $port, $name, "hello", $t, "200");
    get($ip, $port, $name, $t, "404");
    sleep(2);
    get($ip, $port, $name, $t, "200");
    view($ip, $port, $name, "view", -1, $t, "404");
    status($ip, $port, $name, "status", $value, $t, "200");
    status_json($ip, $port, $name, "status_json", $value, $t, "200");
    mq_reset($ip, $port, $name, "reset", $value, $t, "200");
    synctime($ip, $port, $name, "synctime", $value, $t, "200");
    remove($ip, $port, $name, "remove", $value, $t, "200");
}