1

I wanted to add a symfony command as cron job but my hosting server (2freehosting.com) does not allow me to add following command:

 php app/console cache:clear --env=prod --no-debug

Only php path/to/file type of command is allowed.

So I want to create a file clearCache.php to run above command and add it as cron job

php path/to/clearCache.php

How can I call this symfony command in clearCache.php ?

My directory structure:

-app
-bin
-vendor
-src
-public_html
  -bundles
  -app.php
  .....
-clearCache.php

3 Answers 3

1

You can use bash script like clearCache.sh

#!/bin/bash

/path/to/php /path/to/app/console cache:clear --env=prod --no-debug
Sign up to request clarification or add additional context in comments.

Comments

0

assuming you are using linux, you could create an alias:

alias symfony-cc="php path/to/app/console cache:clear --env=prod --no-debug"

Comments

0

Remember that clear cache means remove folders and files in app/cache. So you can use this trick

Create clear.php file in web folder and put

<?php // get all file names
$str = __DIR__.'/../app/cache/';

function recursiveDelete($str){
if(is_file($str)){
    return @unlink($str);
}
elseif(is_dir($str)){
    $scan = glob(rtrim($str,'/').'/*');
    foreach($scan as $index=>$path){
        recursiveDelete($path);
    }
    return @rmdir($str);
}
}

recursiveDelete($str);

//here you can redirect to any page
echo(__DIR__.'/../app/cache/*'.' -> Clear completed'); 

Then access by localhost/clear.php or yoursite.com/clear.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.