diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index a8eb59d0..46ca9c5e 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -222,7 +222,9 @@ public function __construct( $this->client = (new Client()) ->setEndpoint($endpoint) ->setProject($project) - ->setKey($key); + ->setKey($key) + ->setConnectTimeout(static::CONNECT_TIMEOUT) + ->setTimeout(static::REQUEST_TIMEOUT); $this->functions = new Functions($this->client); $this->messaging = new Messaging($this->client); diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 61443459..4bbee7d3 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -140,7 +140,9 @@ public function __construct( $this->client = (new Client()) ->setEndpoint($endpoint) ->setProject($projectId) - ->setKey($key); + ->setKey($key) + ->setConnectTimeout(static::CONNECT_TIMEOUT) + ->setTimeout(static::REQUEST_TIMEOUT); $this->users = new Users($this->client); $this->teams = new Teams($this->client); diff --git a/src/Migration/Target.php b/src/Migration/Target.php index 777609f2..d3332cf7 100644 --- a/src/Migration/Target.php +++ b/src/Migration/Target.php @@ -4,6 +4,23 @@ abstract class Target { + /** + * Seconds to wait for a remote to accept the connection. + */ + public const int CONNECT_TIMEOUT = 10; + + /** + * Seconds a request may go without receiving a byte before it is abandoned. + * Transfers of any length stay alive as long as data keeps arriving. + */ + public const int STALL_TIMEOUT = 30; + + /** + * Seconds an Appwrite SDK request may take in total. The SDK transport only + * takes a total timeout; its requests are single API pages and file chunks. + */ + public const int REQUEST_TIMEOUT = 30; + /** * Global Headers * @@ -118,6 +135,9 @@ protected function call( \curl_setopt($ch, CURLOPT_USERAGENT, php_uname('s').'-'.php_uname('r').':php-'.phpversion()); \curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); \curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + \curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, static::CONNECT_TIMEOUT); + \curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1); + \curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, static::STALL_TIMEOUT); \curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$responseHeaders) { $len = strlen($header); $header = explode(':', strtolower($header), 2);