@@ -71,7 +71,7 @@ public function __construct(string $url, string $text = null, string $file = nul
7171 public function test (bool $ testLocations = true , bool $ testFragment = true , bool $ cache = true ): self
7272 {
7373 if (!$ this ->isTested () || !$ cache ) {
74- $ test = self ::testUrl ($ this ->getSolvedUrl (), $ this ->isExternal (), $ testFragment, $ this -> getFile () );
74+ $ test = self ::testUrl ($ this ->getSolvedUrl (), $ this ->isExternal (), $ testFragment );
7575 $ this ->headers = $ test ['headers ' ];
7676 $ this ->code = $ test ['code ' ];
7777 $ this ->location = null === $ test ['location ' ] ? null : new TestableUrl ($ test ['location ' ], null , $ this ->getFile (), $ this ->getLine (), null , false , $ testLocations );
@@ -249,9 +249,12 @@ public function isInternal(): bool
249249 * @param string $url The URL istsel
250250 * @param bool|null $external If it's an external URL or not
251251 * @param bool $testFragment If the eventual fragment/hash/anchor part should be tested
252+ * @param int $retryCount Number of retries on time out
253+ * @param int $retryDelay Delay in seconds before retrying
254+ * @param int $tryNumber Try number (first try is numbered 1)
252255 * @return array ['headers' => null|array, 'code' => int, 'location' => null|string, 'fragment_found' => null|bool]
253256 */
254- public static function testUrl (string $ url , bool $ external = null , bool $ testFragment = true ): array
257+ public static function testUrl (string $ url , bool $ external = null , bool $ testFragment = true , int $ retryCount = 1 , int $ retryDelay = 300 , int $ tryNumber = 1 ): array
255258 {
256259 $ headers = null ;
257260 $ code = self ::NOT_TESTABLE_CODE ;
@@ -324,6 +327,11 @@ public static function testUrl(string $url, bool $external = null, bool $testFra
324327 }
325328 }
326329 break ;
330+ case 522 : // Connection Timed Out
331+ if ($ tryNumber <= $ retryCount +1 ) {
332+ sleep ($ retryDelay );
333+ return testUrl ($ url , $ external , $ testFragment , $ retryCount , $ retryDelay , $ tryNumber ++);
334+ }
327335 case 400 : // Bad Request
328336 case 401 : // Unauthorized
329337 case 403 : // Forbidden
0 commit comments