[www-doc] [Git][VideoLAN.org/websites][master] Download data using cURL if available

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Tue Dec 2 13:12:15 UTC 2025



Jean-Baptiste Kempf pushed to branch master at VideoLAN organization / websites


Commits:
4997351d by Marvin Scholz at 2025-12-02T14:11:45+01:00
Download data using cURL if available

This is faster and more reliable than file_get_contents.

- - - - -


1 changed file:

- www.videolan.org/vlc/stats/downloads.php


Changes:

=====================================
www.videolan.org/vlc/stats/downloads.php
=====================================
@@ -38,9 +38,49 @@
         echo "<td style='text-align: right;'>".number_format($n,0,"."," ")."</td>";
     }
 
+    function fetch_fallback($url)
+    {
+        $ctx = stream_context_create(array(
+           'http' => array(
+               'protocol_version' => 1.1,
+               'timeout' => 5,
+           ),
+        ));
+       $body = file_get_contents($json_url, false, $ctx);
+       if ($body === false) {
+           throw new Exception('Unable to fetch ' . $json_url);
+       }
+       return $body;
+    }
+
+    function fetch_curl($url)
+    {
+        $ctx = curl_init();
+        curl_setopt($ctx, CURLOPT_URL, $url);
+        curl_setopt($ctx, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ctx, CURLOPT_TIMEOUT, 5);
+        curl_setopt($ctx, CURLOPT_FOLLOWLOCATION, true);
+        curl_setopt($ctx, CURLOPT_HEADER, 0);
+        curl_setopt($ctx, CURLOPT_VERBOSE, false);
+
+        $body = curl_exec($ctx);
+        $status = curl_getinfo($ctx, CURLINFO_RESPONSE_CODE);
+
+        if ($body === false || $status !== 200) {
+            throw new Exception('Unable to fetch ' . $url);
+        }
+
+        return $body;
+    }
+
     function mirrorbits_fetch($json_url)
     {
-       $json_file = file_get_contents($json_url);
+       if (extension_loaded('curl')) {
+           $json_file = fetch_curl($json_url);
+       } else {
+           $json_file = fetch_fallback($json_url);
+       }
+
        $json = json_decode($json_file);
        if (is_int($json->Total))
        {
@@ -644,4 +684,3 @@
 </div>
 
 <?php footer('$Id$'); ?>
-



View it on GitLab: https://code.videolan.org/VideoLAN.org/websites/-/commit/4997351d88b9a3f3cdb7356264260bbc499039cd

-- 
View it on GitLab: https://code.videolan.org/VideoLAN.org/websites/-/commit/4997351d88b9a3f3cdb7356264260bbc499039cd
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the www-doc mailing list