Skip to content

Commit

Permalink
Timeout if URL checking takes a while
Browse files Browse the repository at this point in the history
  • Loading branch information
ejb committed Feb 3, 2016
1 parent 138db76 commit a68464c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ Add a file called *proxy.php* to the config directory. Within the file, use [`st

## Changelog

### 2.0.1

- Shorter timeout when checking URL validity

### 2.0.0

- Simplified proxy configuration
Expand Down
2 changes: 1 addition & 1 deletion api/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// error_reporting(0);
error_reporting(0);
header('Content-Type: application/json');

if (isset($_GET['url']) && $_GET['url'] !== '') {
Expand Down
17 changes: 12 additions & 5 deletions api/scraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ function checkUrl( $url ) {
}
$item_url = $schema[$i]['contents'];
if (!empty($item_url)) {
file_get_contents( $item_url );
$headerStatus = checkHeaderStatus($http_response_header, $strict);
$schema[$i]['_requestHeader'] = $http_response_header;
if ( !is_null($http_response_header) && ($headerStatus === false) ) {
$schema[$i]['ok'] = false;
try {
$ctx = stream_context_create(array(
'http' => array('timeout' => 2)
));
file_get_contents( $item_url );
$headerStatus = checkHeaderStatus($http_response_header, $strict);
$schema[$i]['_requestHeader'] = $http_response_header;
if ( !is_null($http_response_header) && ($headerStatus === false) ) {
$schema[$i]['ok'] = false;
}
} catch (Exception $e) {

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h3>{{group}}</h3>

</div>

<p class="footer"><a target="_self" ng-href="./api/index.php?url={{currentUrl}}">API version of this check</a> | The Meta Tag Checker. v2.0.0 | <a href="https://github.com/dowjones/the-meta-tag-checker">View source on Github</a></p>
<p class="footer"><a target="_self" ng-href="./api/index.php?url={{currentUrl}}">API version of this check</a> | The Meta Tag Checker. v2.0.1 | <a href="https://github.com/dowjones/the-meta-tag-checker">View source on Github</a></p>



Expand Down

0 comments on commit a68464c

Please sign in to comment.