I'm looking for solution/pointers of how to flush cache externally. (im quite new to magento and php)
I've been implementing a lot of magento functionality into my filemaker database using rest api, this includes a visual front page editor that updates a static html block.
problem is for any changes to be visible on the main site, i need to go into magento admin panel and flush cache manually everytime any change is made.
is it possible to maybe create a php file of some sort that would reside on my machine(not the magento server) which i can then trigger to flush the cache?
Solved! Go to Solution.
Hello @roman_polevecko,
For an external file, Please create cache.php in Magento root directory and add code it, I have mentioned in the above comment.
After you can clear cache by using url: https://{magentobaseurl}/cache.php
--
If my answer is useful, please give Kudos & Accept as Solution
Hello @roman_polevecko,
Please create a external file and run below script. (Take care of magento include path)
use Magento\Framework\App\Bootstrap; include('../app/bootstrap.php'); $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); try{ $_cacheTypeList = $objectManager->create('Magento\Framework\App\Cache\TypeListInterface'); $_cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool'); $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice'); foreach ($types as $type) { $_cacheTypeList->cleanType($type); } foreach ($_cacheFrontendPool as $cacheFrontend) { $cacheFrontend->getBackend()->clean(); } }catch(Exception $e){ echo $msg = 'Error : '.$e->getMessage();die(); }
You can also clear via command line
php bin/magento cache:flush php bin/magento cache:clean
--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"
Kindly refer below links for clear cache,
https://www.rakeshjesadiya.com/how-to-clear-or-flush-cache-programmatically-in-magento-2/
I hope its works for you.
Thank you so much! Would you be able to help me to figure out how to set the path for this script assuming I'm accessing from external machine?
Would script have to live on the server?
Sorry, I know it's probably basic but I've only done C programming before and been kinda thrown into a deep end with Magento here. :/
Hello @roman_polevecko,
For an external file, Please create cache.php in Magento root directory and add code it, I have mentioned in the above comment.
After you can clear cache by using url: https://{magentobaseurl}/cache.php
--
If my answer is useful, please give Kudos & Accept as Solution
Hello @gelanivishal ,
I tried your script and it seems to work, in fact the contents of the folder (var / cache /) are deleted but without any effect ... I continue to see the administration area without a template.
thanks in advance.