diff --git a/README.md b/README.md index 64898e9..5665180 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ You may use the following code block below as a template, which has some good de 'protocol' => env('DB_PROTOCOL', 'https'), 'cache_session_token' => env('DB_CACHE_SESSION_TOKEN', true), // set to false to log out after each reqeust. This can be slower than re-using a session token, but allows for globals to be set for individual user values. 'empty_strings_to_null' => env('DB_EMPTY_STRINGS_TO_NULL', true), // set to false to return empty strings instead of null values when fields are empty in FileMaker + 'request_timeout' => env('DB_REQUEST_TIMEOUT', 30), // set the request timeout in seconds (default 30) ] ``` You should add one database connection configuration for each FileMaker database you will be connecting to. Each file can have completely different configurations, and can even be on different servers. @@ -389,6 +390,12 @@ FM::setGlobalFields() // not chainable ->getLayoutMetadata() ``` +#### Request customization methods +```php +->setRetries($retries) // set the number of retries for a request (value of 2 will make 3 requests in total) +->setTimeout($timeout) // set the timeout for a request in seconds +``` + #### Examples: Perform a find for a person named Jaina ```php diff --git a/src/Services/FileMakerConnection.php b/src/Services/FileMakerConnection.php index 9e8e6a2..9ab9afd 100644 --- a/src/Services/FileMakerConnection.php +++ b/src/Services/FileMakerConnection.php @@ -35,30 +35,33 @@ class FileMakerConnection extends Connection protected int $attempts = 2; + protected int $timeout = 30; + protected bool $shouldCacheSessionToken = true; protected ?string $sessionTokenCacheKey = null; protected bool $emptyStringToNull = true; + /** + * Crazy high number of records to return. + * Used to get an empty set when using a whereIn with no values. + */ + public const CRAZY_RECORDS_AMOUNT = 1000000000000000000; + public function __construct($pdo, $database = '', $tablePrefix = '', array $config = []) { - $this->emptyStringToNull = $config['empty_strings_to_null'] ?? true; $this->shouldCacheSessionToken = $config['cache_session_token'] ?? true; // set the session cache key with the name of the connection to support multiple connections $this->sessionTokenCacheKey = 'eloquent-filemaker-session-token-' . $config['name']; + $this->setTimeout($config['request_timeout'] ?? 30); + parent::__construct($pdo, $database, $tablePrefix, $config); } - /** - * Crazy high number of records to return. - * Used to get an empty set when using a whereIn with no values. - */ - public const CRAZY_RECORDS_AMOUNT = 1000000000000000000; - /** * @param string $layout * @return $this @@ -717,7 +720,9 @@ protected function prepareRequestForSending($request = null) } } - $request->retry($this->attempts, 100, fn () => true, false)->withToken($this->sessionToken); + $request->timeout($this->timeout) + ->retry($this->attempts, 100, fn () => true, false) + ->withToken($this->sessionToken); return $request; } @@ -850,6 +855,13 @@ public function setRetries($retries) return $this; } + public function setTimeout($timeout) + { + $this->timeout = $timeout; + + return $this; + } + protected function getDefaultQueryGrammar() { return new FMGrammar;