Skip to content

Commit 81338b0

Browse files
Add setTimeout method to FileMakerConnection
- Adds a method to set the timeout at runtime - Adds a config value to provide default value for all requests
1 parent 1fe2cdb commit 81338b0

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ You may use the following code block below as a template, which has some good de
8080
'protocol' => env('DB_PROTOCOL', 'https'),
8181
'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.
8282
'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
83+
'request_timeout' => env('DB_REQUEST_TIMEOUT', 30), // set the request timeout in seconds (default 30)
8384
]
8485
```
8586
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
389390
->getLayoutMetadata()
390391
```
391392
393+
#### Request customization methods
394+
```php
395+
->setRetries($retries) // set the number of retries for a request (value of 2 will make 3 requests in total)
396+
->setTimeout($timeout) // set the timeout for a request in seconds
397+
```
398+
392399
#### Examples:
393400
Perform a find for a person named Jaina
394401
```php

src/Services/FileMakerConnection.php

+20-8
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,33 @@ class FileMakerConnection extends Connection
3535

3636
protected int $attempts = 2;
3737

38+
protected int $timeout = 30;
39+
3840
protected bool $shouldCacheSessionToken = true;
3941

4042
protected ?string $sessionTokenCacheKey = null;
4143

4244
protected bool $emptyStringToNull = true;
4345

46+
/**
47+
* Crazy high number of records to return.
48+
* Used to get an empty set when using a whereIn with no values.
49+
*/
50+
public const CRAZY_RECORDS_AMOUNT = 1000000000000000000;
51+
4452
public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
4553
{
46-
4754
$this->emptyStringToNull = $config['empty_strings_to_null'] ?? true;
4855
$this->shouldCacheSessionToken = $config['cache_session_token'] ?? true;
4956

5057
// set the session cache key with the name of the connection to support multiple connections
5158
$this->sessionTokenCacheKey = 'eloquent-filemaker-session-token-' . $config['name'];
5259

60+
$this->setTimeout($config['request_timeout'] ?? 30);
61+
5362
parent::__construct($pdo, $database, $tablePrefix, $config);
5463
}
5564

56-
/**
57-
* Crazy high number of records to return.
58-
* Used to get an empty set when using a whereIn with no values.
59-
*/
60-
public const CRAZY_RECORDS_AMOUNT = 1000000000000000000;
61-
6265
/**
6366
* @param string $layout
6467
* @return $this
@@ -717,7 +720,9 @@ protected function prepareRequestForSending($request = null)
717720
}
718721
}
719722

720-
$request->retry($this->attempts, 100, fn () => true, false)->withToken($this->sessionToken);
723+
$request->timeout($this->timeout)
724+
->retry($this->attempts, 100, fn () => true, false)
725+
->withToken($this->sessionToken);
721726

722727
return $request;
723728
}
@@ -850,6 +855,13 @@ public function setRetries($retries)
850855
return $this;
851856
}
852857

858+
public function setTimeout($timeout)
859+
{
860+
$this->timeout = $timeout;
861+
862+
return $this;
863+
}
864+
853865
protected function getDefaultQueryGrammar()
854866
{
855867
return new FMGrammar;

0 commit comments

Comments
 (0)