0

現在、スプレッドシート(​​Webサイトのリストを含む)をデータベースにインポートできます。ボタンをクリックすると、データベース内のドメインごとにGoogleがインデックスに登録したページ数が取得されます。

約400リクエストまでは問題なく動作し、その後、リクエストは何も返されません。私が間違って何をしているのか、またはこれをどのように機能させるのかわからない-何かアイデアはありますか?

try {
        require('db.php');
        $conn = new PDO ( "mysql:host=localhost;dbname=" . $database, $user, $pass );
        $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $stmt = $conn->query('SELECT `url` FROM domains');
        $stmt->setFetchMode(PDO::FETCH_ASSOC);
        while($row = $stmt->fetch()){
            $id = $row['id'];
            $url = $row['url'];
            $pages = getIndexedPageCount($url);
            if ( $pages > 0 ) {
                $status = 1;
            } else {
                $status = 0;
            }
            $prep = $conn->prepare("
            UPDATE `domains`
                SET
                    url = :url,
                    pages = :pages,
                    status = :status
                WHERE url = :url
            ");
            $prep->execute(array(
                ':url'      =>  $url,
                ':pages'    =>  $pages,
                ':status'   =>  $status
            ));
        }
    } catch ( PDOException $e ) {
        echo 'Error: ' . $e->getMessage();
        exit;
    }


    function getIndexedPageCount($domain) {

    // remove http:// and https://
    if ( strpos( $domain, 'http:' ) == 0 ) { $domain = str_replace('http://', '', $domain); }
    if ( strpos( $domain, 'https:' ) == 0 ) { $domain = str_replace('https://', '', $domain); }

        $content = file_get_contents('https://www.googleapis.com/customsearch/v1?key={{Removed API Key}}&q=site:' . $domain);

        if (strlen($content) > 1) {
            $data = json_decode($content);
            return intval($data->searchInformation->totalResults);
        }

        else {
            echo "Error: URL does not exist.";
        }
    }

どんな助けでも大歓迎です。誰かがアイデアを持っているなら、私はそれを機能させようとします!

4

1 に答える 1

2

Googleに送信できるリクエストの数には制限があります。

詳細については、こちらをご覧くださいhttps://developers.google.com/console/help/#monitoringandfiltering

APIコンソールは次のとおりです:https ://code.google.com/apis/console

現在コンソールCustom Search APIには、Courtesy limit: 100 requests/day

請求にサインアップしていない場合、無料使用量の割り当てを超える使用量は失敗します。請求を有効にすると、1日あたり100件の無料クエリを引き続き受け取ることができます。ただし、追加のすべてのリクエストについては、1000クエリあたり5ドル、1日あたり最大10,000クエリの料金が請求されます。

于 2012-10-30T20:39:32.407 に答える