コード例 #1
0
function findresults($term)
{
    global $terms, $search_results, $base_terms, $base_url;
    $url = $base_url . urlencode("how to " . $term);
    $url = $base_url . urlencode($term);
    $results = file_get_contents($url);
    if ($results == "") {
        error_log("error getting results, throttling\n");
        array_push($terms, $term);
        throttle();
        return;
    }
    $x = strpos($results, "new Array");
    if ($x === false) {
        error_log("got {$results} for {$url}");
        return;
    }
    $x += strlen("new Array");
    $y = strpos($results, "new Array", $x + 1);
    $urls = substr($results, $x, $y - $x - 2);
    $urls = cleanup($urls);
    if ($urls == "") {
        return;
    }
    // trim the results
    $url_array = explode(",", $urls);
    $x = $y + strlen("new Array");
    $y = strpos($results, "new Array", $x + 1);
    $results = substr($results, $x, $y - $x - 2);
    $results = cleanup($results);
    $results = preg_replace('/([0-9]),([0-9])/', '$1$2', $results);
    $results = str_replace(" results", "", $results);
    $count_array = explode(",", $results);
    if (sizeof($url_array) == 10) {
        //print("Adding terms for $term\n");
        foreach ($base_terms as $b) {
            if (strlen($term . $b) < 6) {
                array_push($terms, $term . $b);
            }
        }
        // add a space only if it isn't already there
        if (substr($term, strlen($term) - 1, 1) != ' ') {
            array_push($terms, $term . " ");
            //printf("Adding space to +$term+ -" . substr($term, strlen($term)-1, 1) . "-\n");
        }
        //print("Terms are now " . sizeof($terms) . " long\n");
    }
    //	print_r($array);
    for ($i = 0; $i < sizeof($url_array); $i++) {
        $a = $url_array[$i];
        $x = array();
        $x[0] = $term;
        $x[1] = $a;
        $x[2] = $count_array[$i];
        $search_results[] = $x;
    }
    throttle();
}
コード例 #2
0
 public function testThrottleDoesNotThrottleIfThereIsAtLeastOneSecondBetweenCalls()
 {
     throttle();
     $time_a = microtime(true);
     sleep(1);
     $time_b = microtime(true);
     throttle();
     $time_c = microtime(true);
     //Assume it should take no longer than .01 seconds for the throttle function to return
     //when throttle is not being applied
     assertThat($time_c - $time_b, lessThanOrEqualTo(0.01));
 }
コード例 #3
0
ファイル: pipes.php プロジェクト: jubianchi/async-generator
<?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\pipe\{make};
use function jubianchi\async\runtime\{await, all, fork};
use function jubianchi\async\time\{delay, throttle};
$pipe = make();
$i = 0;
await(all(throttle(2500, function () use($pipe, &$i) {
    $pipe->enqueue($i++);
}), throttle(500, function () use($pipe) {
    echo __LINE__;
    var_dump("" . (yield from $pipe->dequeue()) . "");
}), throttle(1000, function () use($pipe) {
    echo __LINE__;
    var_dump("" . (yield from $pipe->dequeue()) . "");
})));
コード例 #4
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;
コード例 #5
0
    $found = false;
    foreach ($matches[0] as $url) {
        $url = substr($url, 6, strlen($url) - 7);
        // check for cache article
        if (strpos($url, "/search?q=cache") !== false || strpos($url, "google.com/") !== false) {
            continue;
        }
        $count++;
        $domain = str_replace("http://", "", $url);
        $domain = substr($domain, 0, strpos($domain, '/'));
        if (strpos($domain, "wikihow.com") !== false) {
            $sql = "INSERT INTO google_monitor_results (gmr_page, gmr_position) VALUES ({$page_id}, {$count});";
            $dbw->query($sql);
            $found = true;
            break;
        }
    }
    if (!$found) {
        $sql = "INSERT INTO google_monitor_results (gmr_page, gmr_position) VALUES ({$page_id}, 0);";
        $dbw->query($sql);
    }
}
// load queries from the database
$titles = getTitles();
foreach ($titles as $title) {
    checkGoogle($title->getText(), $title->getArticleID(), $dbw);
    throttle();
}
?>

コード例 #6
0
ファイル: test.php プロジェクト: standardpavel/Throttle
<?php

session_start();
require 'throttle.php';
if (isset($_GET['postComment'])) {
    throttle(array('throttleKey' => 'rateLimitYo', 'id' => 'submit-comment', 'timeout' => 60, 'passes' => 3, 'interval' => 15, 'throttled' => function ($seconds) {
        // They've been throttles
        die("Cannot login, you've been throttled, baby. " . $seconds . " seconds left. <a href=\"javascript:window.location.reload()\">Refresh</a>");
    }));
    // Continue Code
}
?>
<!doctype html>
<html lang="en">
	<head>
		<title>Throttle Test</title>
	</head>
	<body>
		<p>Here is an example of the rate throttler. If you click "Submit Comment" link below <b>more</b> than 3 times within 15 seconds, you will see a message throttling you for 60 seconds.</p>
		<a href="?postComment">Submit Comment</a>
		<?php 
echo '<pre>' . print_r($_SESSION, true) . '</pre>';
?>
	</body>
</html>