@@ -793,6 +793,12 @@ flagsmith.close();
793
793
flagsmith .close ();
794
794
```
795
795
796
+ </TabItem >
797
+ <TabItem value =" php " label =" PHP " >
798
+
799
+ Since PHP does not share state between requests, you ** have** to implement caching to get the benefits of Local
800
+ Evaluation mode. Please see [ caching] ( #caching ) below.
801
+
796
802
</TabItem >
797
803
</Tabs >
798
804
@@ -1572,6 +1578,51 @@ router.get('/', function (req, res, next) {
1572
1578
});
1573
1579
```
1574
1580
1581
+ </TabItem >
1582
+ <TabItem value =" php " label =" PHP " >
1583
+
1584
+ ``` php
1585
+ $flagsmith = (new Flagsmith(TOKEN));
1586
+ // This will load the environment from cache (or API, if cache does not exist.)
1587
+ $flagsmith->updateEnvironment();
1588
+ ```
1589
+
1590
+ It is recommended to use a psr simple-cache implementation to cache the environment document between multiple requests.
1591
+
1592
+ ``` sh
1593
+ composer require symfony/cache
1594
+ ```
1595
+
1596
+ ``` php
1597
+ $flagsmith = (new Flagsmith(TOKEN))
1598
+ ->withCache(new Psr16Cache(new FilesystemAdapter()));
1599
+ // Cache the environment call to reduce network calls for each and every evaluation.
1600
+ // This will load the environment from cache (or API, if cache does not exist.)
1601
+ $flagsmith->updateEnvironment();
1602
+ ```
1603
+
1604
+ An optional cron job can be added to refresh this cache at a set time depending on your choice. Please set
1605
+ EnvironmentTTL value for this purpose.
1606
+
1607
+ ``` php
1608
+ // the environment will be cached for 100 seconds.
1609
+ $flagsmith = $flagsmith->withEnvironmentTtl(100);
1610
+ $flagsmith->updateEnvironment();
1611
+ ```
1612
+
1613
+ ``` sh
1614
+ * * * 1 40 php index.php # using cli
1615
+ * * * 1 40 curl http://localhost:8000/ # using http
1616
+ ```
1617
+
1618
+ Note:
1619
+
1620
+ - For the environment cache, please use the server key generated from the Flagsmith Settings menu. The key's prefix is
1621
+ ` ser. ` .
1622
+ - The cache is important for concurrent requests. Without the cache, each request in PHP is a different process with its
1623
+ own memory objects. The cache (filesystem or other) would enforce that the network call is reduced to a file system
1624
+ one.
1625
+
1575
1626
</TabItem >
1576
1627
</Tabs >
1577
1628
0 commit comments