Externally, on your network, you have a public IP address that you use to route all your requests to your load balancer, which distributes the load around robin so outside, you cannot make a request to clear the cache on each server one at a time, t Know which one is being used at any given time. However, on your network, each machine has its own internal IP address and can be called directly. Knowing this, you can do funny / weird things that work externally.
The solution I like is to hit a single url and do everything, like http: //www.mywebsite/clearcache.php or something like that. If you like it, read on. Remember that you can get this authentication if you want your administrator to be able to hit this address or, nevertheless, protect it.
You can create logic where you can make one request to clear the cache on all servers. Whatever server receives a request to clear the cache, it will have the same logic to talk to all servers in order to clear its cache. It sounds weird and a bit frankenstein, but here comes the logic assuming that we have 3 servers with IP addresses 10.232.12.1, 10.232.12.2, 10.232.12.3 inside:
1) All servers would have two files called "initiate_clear_cache.php" and "clear_cache.php" that would be the same copies for all servers. 2) "initiate_clear_cache.php" would do a file_get_contents for each machine in the network calling "clear_cache.php" which would include itself for example: file_get_contents('http://10.232.12.1/clear_cache.php'); file_get_contents('http://10.232.12.2/clear_cache.php'); file_get_contents('http://10.232.12.3/clear_cache.php'); 3) The file called "clear_cache.php" is actually doing the cache clearing for its respective machine. 4) You only need to make a single request now such as http:
Let me know if this works for you. I did this in .NET and Node.js, but have not tried it in PHP yet, but I'm sure the concept is the same. :)
source share