summaryrefslogtreecommitdiff
path: root/include/functions.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-04-02 11:41:15 -0700
committerAndrew Dolgov <[email protected]>2013-04-02 11:41:15 -0700
commit2f76e8583db5949a8e4d1179d18bcc2473dcaccf (patch)
tree30a290350e10befd921050cf0f796a25f76fe245 /include/functions.php
parent8ef9645da0374d65683a4ed4762b8f2e6d36016e (diff)
parent9ef8798bec84b3aa86dc699681ea4f21efb3cefa (diff)
Merge pull request #114 from ifireball/tunable-fetches
Allow tuning fetch timeouts from config.php
Diffstat (limited to 'include/functions.php')
-rw-r--r--include/functions.php34
1 files changed, 32 insertions, 2 deletions
diff --git a/include/functions.php b/include/functions.php
index f273e2f80..ee575568a 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -30,6 +30,36 @@
require_once 'config.php';
+ /**
+ * Define a constant if not already defined
+ *
+ * @param string $name The constant name.
+ * @param mixed $value The constant value.
+ * @access public
+ * @return boolean True if defined successfully or not.
+ */
+ function define_default($name, $value) {
+ // Note: performence freaks should define everything in
+ // config.php becasue if will make defined() run much faster,
+ // see comment by 'tris+php at tfconsulting dot com dot au'
+ // here:
+ // http://www.php.net/manual/en/function.defined.php#89886
+ defined($name) or define($name, $value);
+ }
+
+ ///// Some defaults that you can override in config.php //////
+
+ define_default('FEED_FETCH_TIMEOUT', 45);
+ // How may seconds to wait for response when requesting feed from a site
+ define_default('FEED_FETCH_NO_CACHE_TIMEOUT', 15);
+ // How may seconds to wait for response when requesting feed from a
+ // site when that feed wasn't cached before
+ define_default('FILE_FETCH_TIMEOUT', 45);
+ // Default timeout when fetching files from remote sites
+ define_default('FILE_FETCH_CONNECT_TIMEOUT', 15);
+ // How many seconds to wait for initial response from website when
+ // fetching files from remote sites
+
if (DB_TYPE == "pgsql") {
define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
} else {
@@ -308,8 +338,8 @@
array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T', $timestamp)));
}
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : 15);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : 45);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode"));
curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);