summaryrefslogtreecommitdiffstats
path: root/lib/ocsclient.php
diff options
context:
space:
mode:
authorFrank Karlitschek <frank@owncloud.org>2012-10-08 12:00:29 +0200
committerFrank Karlitschek <frank@owncloud.org>2012-10-08 12:00:29 +0200
commite9f04bedd4d57ffd47d9b6e25041da191aaac1e7 (patch)
tree8cf08865c78b761c4df335c859791b020e4951d1 /lib/ocsclient.php
parentb7a5cc2fda1484e8a054820ef026bbaeccf31c77 (diff)
downloadnextcloud-server-e9f04bedd4d57ffd47d9b6e25041da191aaac1e7.tar.gz
nextcloud-server-e9f04bedd4d57ffd47d9b6e25041da191aaac1e7.zip
add a sane socket timeout so that the interface stays responsive with a slow or not working internet connection
Diffstat (limited to 'lib/ocsclient.php')
-rw-r--r--lib/ocsclient.php55
1 files changed, 50 insertions, 5 deletions
diff --git a/lib/ocsclient.php b/lib/ocsclient.php
index 6428a883679..fc2095f5c15 100644
--- a/lib/ocsclient.php
+++ b/lib/ocsclient.php
@@ -62,7 +62,15 @@ class OC_OCSClient{
}
$url=OC_OCSClient::getAppStoreURL().'/content/categories';
- $xml=@file_get_contents($url);
+ // set a sensible timeout of 10 sec to stay responsive even if the server is down.
+ $ctx = stream_context_create(
+ array(
+ 'http' => array(
+ 'timeout' => 10
+ )
+ )
+ );
+ $xml=@file_get_contents($url, 0, $ctx);
if($xml==FALSE) {
return NULL;
}
@@ -103,7 +111,17 @@ class OC_OCSClient{
$filterurl='&filter='.urlencode($filter);
$url=OC_OCSClient::getAppStoreURL().'/content/data?categories='.urlencode($categoriesstring).'&sortmode=new&page='.urlencode($page).'&pagesize=100'.$filterurl.$version;
$apps=array();
- $xml=@file_get_contents($url);
+
+ // set a sensible timeout of 10 sec to stay responsive even if the server is down.
+ $ctx = stream_context_create(
+ array(
+ 'http' => array(
+ 'timeout' => 10
+ )
+ )
+ );
+ $xml=@file_get_contents($url, 0, $ctx);
+
if($xml==FALSE) {
return NULL;
}
@@ -141,7 +159,15 @@ class OC_OCSClient{
}
$url=OC_OCSClient::getAppStoreURL().'/content/data/'.urlencode($id);
- $xml=@file_get_contents($url);
+ // set a sensible timeout of 10 sec to stay responsive even if the server is down.
+ $ctx = stream_context_create(
+ array(
+ 'http' => array(
+ 'timeout' => 10
+ )
+ )
+ );
+ $xml=@file_get_contents($url, 0, $ctx);
if($xml==FALSE) {
OC_Log::write('core','Unable to parse OCS content',OC_Log::FATAL);
return NULL;
@@ -178,7 +204,16 @@ class OC_OCSClient{
}
$url=OC_OCSClient::getAppStoreURL().'/content/download/'.urlencode($id).'/'.urlencode($item);
- $xml=@file_get_contents($url);
+ // set a sensible timeout of 10 sec to stay responsive even if the server is down.
+ $ctx = stream_context_create(
+ array(
+ 'http' => array(
+ 'timeout' => 10
+ )
+ )
+ );
+ $xml=@file_get_contents($url, 0, $ctx);
+
if($xml==FALSE) {
OC_Log::write('core','Unable to parse OCS content',OC_Log::FATAL);
return NULL;
@@ -215,7 +250,17 @@ class OC_OCSClient{
$url=OC_OCSClient::getKBURL().'/knowledgebase/data?type=150&page='.$p.'&pagesize='.$s.$searchcmd;
$kbe=array();
- $xml=@file_get_contents($url);
+
+ // set a sensible timeout of 10 sec to stay responsive even if the server is down.
+ $ctx = stream_context_create(
+ array(
+ 'http' => array(
+ 'timeout' => 10
+ )
+ )
+ );
+ $xml=@file_get_contents($url, 0, $ctx);
+
if($xml==FALSE) {
OC_Log::write('core','Unable to parse knowledgebase content',OC_Log::FATAL);
return NULL;