Centralize HTTP limits

This commit is contained in:
Troy Grunt
2026-02-15 14:57:05 +01:00
parent 923dafecc9
commit cb115bac40
5 changed files with 75 additions and 18 deletions

20
og.php
View File

@@ -1,9 +1,27 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/http-limits.php';
function scanOG(string $url): array {
$og = array();
$html = file_get_contents($url);
$limits = httpLimits();
$ctx = stream_context_create([
'http' => [
'timeout' => $limits['timeout'],
'follow_location' => 1,
'max_redirects' => $limits['max_redirects'],
'user_agent' => $limits['user_agent'],
'ignore_errors' => true
],
'ssl' => [
'verify_peer' => true,
'verify_peer_name' => true
]
]);
$html = @file_get_contents($url, false, $ctx);
if ($html === false || strlen($html) > $limits['max_bytes']) {
return $og;
}
$re = '/<meta (name|property)=("|\')(.*?)("|\').*?content=("|\')(.*?)("|\')/m';
preg_match_all($re, $html, $matches, PREG_SET_ORDER, 0);