* * @author cluries * @link http://cdbit.com * @version 1.0 * @copyright 2012 http://cdbit.com All rights reserved * * ********************************************************* */ if (islocked('douban')) { display(_er('E_LOCKED', 'douban', 'douban'), 0); } if (empty($_REQUEST['oauth_token'])) { display(_er('E_404'), 0); } if ($_SESSION['douban_token'] != $_REQUEST['oauth_token']) { retry(); } import('/library/OAuth.php'); import('/library/doubanoauth.php'); global $cfg_douban; $o = new DoubanOAuth($cfg_douban['key'], $cfg_douban['secret'], $_SESSION['douban_token'], $_SESSION['douban_token_secret']); $token = $o->getAccessToken(); if (!empty($token['oauth_token_secret']) && !empty($token['oauth_token'])) { Encryption::serializeToFile($token, tmpDir('douban.oauth')); lockit('douban'); display('douban认证成功'); } display('douban认证失败'); function retry() { Header("Location:install.php?action=auth");
/** * Get the current tunnel URL from the Ngrok API. * * @return string */ public function currentTunnelUrl() { return retry(20, function () { $body = Request::get($this->tunnelsEndpoint)->send()->body; // If there are active tunnels on the Ngrok instance we will spin through them and // find the one responding on HTTP. Each tunnel has an HTTP and a HTTPS address // but for local testing purposes we just desire the plain HTTP URL endpoint. if (isset($body->tunnels) && count($body->tunnels) > 0) { return $this->findHttpTunnelUrl($body->tunnels); } else { throw new DomainException('Tunnel not established.'); } }, 250); }
function testRetryManyTimes() { $e = null; $i = 0; try { retry(1000, function () use(&$i) { $i++; throw new \RuntimeException('dogecoin'); }); } catch (\Exception $e) { } $this->assertInstanceof('igorw\\FailingTooHardException', $e); $this->assertInstanceof('RuntimeException', $e->getPrevious()); $this->assertSame('dogecoin', $e->getPrevious()->getMessage()); $this->assertSame(1001, $i); }
// Listen for a notification that we have been assigned an opponent. // Note that this uses some dynamic data in the query, due to the // limitations of PostgreSQL's listen syntax. $res = pg_query("LISTEN bot_{$bot['id']};"); if ($res === FALSE) { failure("Failed to listen for matchmaking events."); } pg_free_result($res); // Try every second for thirty seconds as to be assigned an opponent. for ($i = 0; $i < 30; $i++) { // Add this bot to the matchmaking queue. Note that this uses some // dynamic data in the query, due to the limitations of PostgreSQL's // notify syntax. $res = pg_query("NOTIFY matchmaker, '{$bot['id']}';"); if ($res === FALSE) { failure("Failed to notify the matchmaker that this bot is ready for a new game."); } pg_free_result($res); $res = pg_get_notify($db, PGSQL_ASSOC); if ($res !== FALSE) { break; } sleep(1); } // Check whether we're in a game, now that we're out of the loop. check_game(); // If we haven't gotten a notification by now, fail encouragingly. pg_query("BEGIN;"); reset_timeout("session"); retry("Failed to find an opponent to play against within 30 seconds, please try again.", "session");
$sdata = mysql_fetch_array($sresult); $theanswer = $sdata["answer"]; $sp_nextact = strlen($theanswer) > 0 && $theanswer == $answer ? "answered" : "badanswer"; } else { $sp_nextact = $sp_nextact == "answer" ? "badanswer" : $sp_nextact; } echo "<input type=hidden name='sp_nextact' id='sp_nextact' value=\"{$sp_nextact}\">\n"; switch ($sp_nextact) { case "view": inputing($username, $email); break; case "ask": askuser($shandle, $username, $email, $question, $answer); break; case "retry": retry($username, $email); break; case "badanswer": badanswer($shandle, $username, $email, $question, $answer); break; case "answered": answered($shandle, $username, $fullname, $email); break; case "sendmail": break; case "done": break; } ///////////////////////////////////////////////////////////////////////// function inputing($username, $email) {