diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 5af540ff..01035649 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -283,7 +283,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 d64d39d4..4b10c1ba 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -143,7 +143,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 b855d3ce..52d89181 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);