Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Call the command line via the browser

You can mimick the call of the symfony command line via a PHP script called from the browser. For instance, for the command

$ symfony clear-cache

...create a webclearcache.php file in your myproject/web/ directory (where the index.php is) with the following content:

<?php
 
// as we are in the web/ dir, we need to go up one level to get to the project root
chdir(dirname(__FILE__).DIRECTORY_SEPARATOR.'..');
 
include_once('/lib/symfony/pake/bin/pake.php');
 
$pake = pakeApp::get_instance();
try
{
  $ret = $pake->run('/data/symfony/bin/pakefile.php', 'clear-cache');
}
catch (pakeException $e)
{
  print "<strong>ERROR</strong>: ".$e->getMessage();
}
 
?>

You can now clear the cache by calling:

http://myapp.example.com/webclearcache.php

Note: Beware that by letting web access to administration tools, you can compromise the safety of your website.

by Francois Zaninotto on 2006-05-24, tagged cli  pake 

Comments on this snippet

gravatar icon
#1 Sylvain PAPET on 2006-05-24 at 05:01

I got error with the php script, It work with :

[...] include_once('pake.php'); [...] $pake->run(PEAR_INSTALL_DIR.'/data/symfony/bin/pakefile.php', 'clear-cache'); [...]

gravatar icon
#2 Jacopo Romei on 2006-07-31 at 01:26

Check this out too: http://www.symfony-project.com/snippets/snippet/66 Bye!

gravatar icon
#3 Artsiom Trubchyk on 2008-03-09 at 12:06

Updated to use it from action class and symfony 1.0:

{
    // we need to go up one level to get to the project root
    chdir(dirname(__FILE__).DIRECTORY_SEPARATOR.'../../../../../');
 
    include_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/pake/pakeFunction.php');
 
    $pake = pakeApp::get_instance();
    try
    {
      // be quiet
      $pake->do_option("quiet", "");
 
      // run task 
      include_once(sfConfig::get('sf_symfony_data_dir').'/tasks/sfPakeBase.php');
      $ret = $pake->run(sfConfig::get('sf_symfony_data_dir').'/tasks/sfPakeMisc.php', 'clear-cache');
    }
    catch (pakeException $e)
    {
      // to use $error variable in clearcacheError.php template
      $this->error = $e->getMessage();
      return sfView::ERROR;
    }
 
    return sfView::SUCCESS;
 
You need to create an account or log in to post a comment or rate this snippet.