[PHP-WEBMASTER] [web-wiki] cache-user-info-requests: Cache querying for user information, as that requires an HTTP call to main.php.net

Author: Derick Rethans (derickr)
Date: 2025-04-07T17:22:20+01:00

Commit: Cache querying for user information, as that requires an HTTP call to… · php/web-wiki@60940fa · GitHub
Raw diff: https://github.com/php/web-wiki/commit/60940fad6da586c2933e95166b9ede285bb2e21a.diff

Cache querying for user information, as that requires an HTTP call to main.php.net

Changed paths:
  M dokuwiki/lib/plugins/phpcvs/auth.php

Diff:

diff --git a/dokuwiki/lib/plugins/phpcvs/auth.php b/dokuwiki/lib/plugins/phpcvs/auth.php
index 6303bc77..c6d7c2a1 100755
--- a/dokuwiki/lib/plugins/phpcvs/auth.php
+++ b/dokuwiki/lib/plugins/phpcvs/auth.php
@@ -69,41 +69,49 @@ function _setCVSUser($user){
      *
      * @return bool true or int error code
      */
- function _checkCVSPass($user,$pass = ''){
- $post = http_build_query(
- array(
- "token" => getenv("dokuwikitoken"),
- "username" => $user,
- "password" => $pass,
- ), '', '&'
- );
-
- $opts = array(
- "method" => "POST",
- "header" => "Content-type: application/x-www-form-urlencoded",
- "content" => $post,
- );
-
- $ctx = stream_context_create(array("http" => $opts));
-
- $s = file_get_contents("https://main.php.net/fetch/cvsauth.php", false, $ctx);
-
- $a = unserialize($s);
- /*
- define("E_UNKNOWN", 0);
- define("E_USERNAME", 1);
- define("E_PASSWORD", 2);
- */
- if (!is_array($a)) {
- return 0;
- }
- if (isset($a["errno"])) {
- return (int)$a["errno"];
- }
+ function _checkCVSPass($user, $pass = '')
+ {
+ static $userCache = ;
+
+ if (!array_key_exists($user, $userCache)) {
+ $post = http_build_query(
+ array(
+ "token" => getenv("dokuwikitoken"),
+ "username" => $user,
+ "password" => $pass,
+ ), '', '&'
+ );
+
+ $opts = array(
+ "method" => "POST",
+ "header" => "Content-type: application/x-www-form-urlencoded",
+ "content" => $post,
+ );
+
+ $ctx = stream_context_create(array("http" => $opts));
+
+ $s = file_get_contents("https://main.php.net/fetch/cvsauth.php", false, $ctx);
+
+ $a = unserialize($s);
+ $userCache[$user] = $a;
+ } else {
+ $a = $userCache[$user];
+ }
+ /*
+ define("E_UNKNOWN", 0);
+ define("E_USERNAME", 1);
+ define("E_PASSWORD", 2);
+ */
+ if (!is_array($a)) {
+ return 0;
+ }
+ if (isset($a["errno"])) {
+ return (int)$a["errno"];
+ }

- $this->_setCVSUser($user);
+ $this->_setCVSUser($user);

- return true;
+ return true;
     }

     /**