Centralize HTTP limits
This commit is contained in:
20
og.php
20
og.php
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user