Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
253fbea2
Commit
253fbea2
authored
12 years ago
by
Staratel
Committed by
Chris Leppanen
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #1480902 by Staratel | faunt: Added Are there timeouts on Feed importers?.
parent
b32b4319
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.txt
+2
-0
2 additions, 0 deletions
README.txt
feeds.install
+7
-0
7 additions, 0 deletions
feeds.install
libraries/http_request.inc
+10
-5
10 additions, 5 deletions
libraries/http_request.inc
plugins/FeedsHTTPFetcher.inc
+27
-2
27 additions, 2 deletions
plugins/FeedsHTTPFetcher.inc
with
46 additions
and
7 deletions
README.txt
+
2
−
0
View file @
253fbea2
...
...
@@ -191,6 +191,8 @@ Default: 50
Name: http_request_timeout
Default: 15
Description: Timeout in seconds to wait for an HTTP get request to finish.
Note: This setting could be overridden per importer in admin UI :
admin/structure/feeds/<your_importer>/settings/<your_fetcher> page.
Name: feeds_never_use_curl
Default: FALSE
...
...
This diff is collapsed.
Click to expand it.
feeds.install
+
7
−
0
View file @
253fbea2
...
...
@@ -5,6 +5,13 @@
* Schema definitions install/update/uninstall hooks.
*/
/**
* Implement hook_uninstall()
*/
function
feeds_uninstall
()
{
variable_del
(
'http_request_timeout'
);
}
/**
* Implements hook_schema().
*/
...
...
This diff is collapsed.
Click to expand it.
libraries/http_request.inc
+
10
−
5
View file @
253fbea2
...
...
@@ -77,11 +77,13 @@ function http_request_get_common_syndication($url, $settings = NULL) {
* If the URL uses authentication, supply the password.
* @param bool $accept_invalid_cert
* Whether to accept invalid certificates.
* @param integer $timeout
* Timeout in seconds to wait for an HTTP get request to finish.
*
* @return stdClass
* An object that describes the data downloaded from $url.
*/
function
http_request_get
(
$url
,
$username
=
NULL
,
$password
=
NULL
,
$accept_invalid_cert
=
FALSE
)
{
function
http_request_get
(
$url
,
$username
=
NULL
,
$password
=
NULL
,
$accept_invalid_cert
=
FALSE
,
$timeout
=
NULL
)
{
// Intra-pagedownload cache, avoid to download the same content twice within
// one page download (it's possible, compatible and parse calls).
static
$download_cache
=
array
();
...
...
@@ -89,6 +91,9 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
return
$download_cache
[
$url
];
}
// Determine request timeout.
$request_timeout
=
!
empty
(
$timeout
)
?
$timeout
:
variable_get
(
'http_request_timeout'
,
30
);
if
(
!
$username
&&
valid_url
(
$url
,
TRUE
))
{
// Handle password protected feeds.
$url_parts
=
parse_url
(
$url
);
...
...
@@ -168,7 +173,7 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
curl_setopt
(
$download
,
CURLOPT_HEADER
,
TRUE
);
curl_setopt
(
$download
,
CURLOPT_RETURNTRANSFER
,
TRUE
);
curl_setopt
(
$download
,
CURLOPT_ENCODING
,
''
);
curl_setopt
(
$download
,
CURLOPT_TIMEOUT
,
variable_get
(
'http_
request_timeout
'
,
30
)
);
curl_setopt
(
$download
,
CURLOPT_TIMEOUT
,
$
request_timeout
);
if
(
$accept_invalid_cert
)
{
curl_setopt
(
$download
,
CURLOPT_SSL_VERIFYPEER
,
0
);
}
...
...
@@ -212,7 +217,7 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
}
}
else
{
$result
=
drupal_http_request
(
$url
,
array
(
'headers'
=>
$headers
,
'timeout'
=>
variable_get
(
'http_
request_timeout
'
,
30
)
));
$result
=
drupal_http_request
(
$url
,
array
(
'headers'
=>
$headers
,
'timeout'
=>
$
request_timeout
));
}
$result
->
code
=
isset
(
$result
->
code
)
?
$result
->
code
:
200
;
...
...
@@ -228,7 +233,7 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
// It's a tragedy, this file must exist and contain good data.
// In this case, clear cache and repeat.
cache_clear_all
(
'feeds_http_download_'
.
md5
(
$url
),
'cache'
);
return
http_request_get
(
$url
,
$username
,
$password
);
return
http_request_get
(
$url
,
$username
,
$password
,
$accept_invalid_cert
,
$request_timeout
);
}
}
...
...
This diff is collapsed.
Click to expand it.
plugins/FeedsHTTPFetcher.inc
+
27
−
2
View file @
253fbea2
...
...
@@ -13,6 +13,7 @@ feeds_include_library('PuSHSubscriber.inc', 'PuSHSubscriber');
class
FeedsHTTPFetcherResult
extends
FeedsFetcherResult
{
protected
$url
;
protected
$file_path
;
protected
$timeout
;
/**
* Constructor.
...
...
@@ -27,12 +28,20 @@ class FeedsHTTPFetcherResult extends FeedsFetcherResult {
*/
public
function
getRaw
()
{
feeds_include_library
(
'http_request.inc'
,
'http_request'
);
$result
=
http_request_get
(
$this
->
url
);
$result
=
http_request_get
(
$this
->
url
,
NULL
,
NULL
,
NULL
,
$this
->
timeout
);
if
(
!
in_array
(
$result
->
code
,
array
(
200
,
201
,
202
,
203
,
204
,
205
,
206
)))
{
throw
new
Exception
(
t
(
'Download of @url failed with code !code.'
,
array
(
'@url'
=>
$this
->
url
,
'!code'
=>
$result
->
code
)));
}
return
$this
->
sanitizeRaw
(
$result
->
data
);
}
public
function
getTimeout
()
{
return
$this
->
timeout
;
}
public
function
setTimeout
(
$timeout
)
{
$this
->
timeout
=
$timeout
;
}
}
/**
...
...
@@ -48,7 +57,10 @@ class FeedsHTTPFetcher extends FeedsFetcher {
if
(
$this
->
config
[
'use_pubsubhubbub'
]
&&
(
$raw
=
$this
->
subscriber
(
$source
->
feed_nid
)
->
receive
()))
{
return
new
FeedsFetcherResult
(
$raw
);
}
return
new
FeedsHTTPFetcherResult
(
$source_config
[
'source'
]);
$fetcher_result
=
new
FeedsHTTPFetcherResult
(
$source_config
[
'source'
]);
// When request_timeout is empty, the global value is used.
$fetcher_result
->
setTimeout
(
$this
->
config
[
'request_timeout'
]);
return
$fetcher_result
;
}
/**
...
...
@@ -95,6 +107,7 @@ class FeedsHTTPFetcher extends FeedsFetcher {
'auto_detect_feeds'
=>
FALSE
,
'use_pubsubhubbub'
=>
FALSE
,
'designated_hub'
=>
''
,
'request_timeout'
=>
NULL
,
);
}
...
...
@@ -124,6 +137,18 @@ class FeedsHTTPFetcher extends FeedsFetcher {
'edit-use-pubsubhubbub'
=>
array
(
1
),
),
);
// Per importer override of global http request timeout setting.
$form
[
'request_timeout'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Request timeout'
),
'#description'
=>
t
(
'Timeout in seconds to wait for an HTTP get request to finish.</br>'
.
'<b>Note:</b> this setting will override the global setting.</br>'
.
'When left empty, the global value is used.'
),
'#default_value'
=>
$this
->
config
[
'request_timeout'
],
'#element_validate'
=>
array
(
'element_validate_integer_positive'
),
'#maxlength'
=>
3
,
'#size'
=>
30
,
);
return
$form
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment