从php文件运行symfony 2命令

从php文件运行symfony 2命令,symfony,symfony-2.3,Symfony,Symfony 2.3,我想添加一个symfony命令作为cron作业,但我的托管服务器(2freehosting.com)不允许我添加以下命令: php app/console cache:clear --env=prod --no-debug 只允许使用php路径/to/file类型的命令 所以我想创建一个文件clearCache.php来运行上述命令,并将其添加为cron作业 php path/to/clearCache.php 如何在clearCache.php中调用此symfony命令 我的目录结构:

我想添加一个symfony命令作为cron作业,但我的托管服务器(2freehosting.com)不允许我添加以下命令:

 php app/console cache:clear --env=prod --no-debug
只允许使用
php路径/to/file
类型的命令

所以我想创建一个文件clearCache.php来运行上述命令,并将其添加为cron作业

php path/to/clearCache.php
如何在clearCache.php中调用此symfony命令

我的目录结构:

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

您可以使用bash脚本,如
clearCache.sh

#!/bin/bash

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

您可以使用bash脚本,如
clearCache.sh

#!/bin/bash

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

假设您使用的是linux,您可以创建一个别名:

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

假设您使用的是linux,您可以创建一个别名:

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

请记住,清除缓存意味着删除应用程序/缓存中的文件夹和文件。所以你可以使用这个技巧

在web文件夹中创建clear.php文件并放置

<?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'); 

记住,清除缓存意味着删除app/cache中的文件夹和文件。所以你可以使用这个技巧

在web文件夹中创建clear.php文件并放置

<?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');