Could not open input file: admin/cli/purge_caches

Could not open input file: admin/cli/purge_caches

by David Maldonado -
Number of replies: 7

Good Afternoon dear Moodlers,


I have a problem with my Moodle environment. This morning  moodle was giving an error message stating "Coding error detected, it must be fixed by a programmer: Failed to unserialise data from file. Either failed to read, or failed to write."

I thought "no problem" and tried to run the php /moodle/admin/cli/purge_caches.php command as per this post https://moodle.org/mod/forum/discuss.php?d=240739 because it has worked for me in the past. To my surprise, I get an error message stating "Could not open input file: admin/cli/purge_caches" So I went the quick/lazy way and just installed a fresh copy of the code and my moodle started working fine.

However, I tried the php /moodle/admin/cli/purge_caches.php command again because I know I WILL need it in the future, and I get the same error message. And I am very scared because I don't want to be downloading a copy of new code every time I get the Coding error.

So, I have 2 questions:

1. How can I prevent the "Coding error detected..." problem from happening? I thought I was smart and I put this line in my cron to run this command every 2 weeks "0 2 * * 2 sudo -u www-data /usr/bin/php admin/cli/purge_caches.php" however, now I get the "Could not open input file: admin/cli/purge_caches" error which leads to my second question

2. How do I fix it so that I can run the "/usr/bin/php admin/cli/purge_caches" command and so that it clears the caches as it's supposed to?


Kind thanks for your help with this.


David Maldonado

Average of ratings: -
In reply to David Maldonado

Re: Could not open input file: admin/cli/purge_caches

by Ken Task -
Picture of Particularly helpful Moodlers

A couple of things ...

Run from command line:

cd /path_to_moodle_code/ [ENTER]

You can then run: php admin/cli/purge_caches.php ... note that purge_caches has a .php extension.

When setting up crons one might need to give full paths to everything ... just like the start:

* /usr/bin/php ... so also the /full_path/to_moodle_code/directory/admin/cli/purge_caches.php

*Do NOT use the example above ... + do NOT use the example below.  The * and + are NOT part of the command ... just used here to indicate where to look. ;)

Moodle code is located in /var/www/html/moodle/ might not be same on your system.

+ To run Cron: /usr/bin/php /var/www/html/moodle/admin/cli/purge_caches.php

To run from command line logged on as a root user (or sudo):

One could: cd /var/www/html/moodle/

Then run php admin/cli/purge_caches.php

OR

one could

php /var/www/html/moodle/admin/cli/purge_caches.php

'spirit of sharing', Ken


Average of ratings: Useful (2)
In reply to Ken Task

Re: Could not open input file: admin/cli/purge_caches

by David Maldonado -

Thank you Ken,

I ran the command below:


moodle$ sudo php admin/cli/purge_caches.php
moodle$

And it didn't give any error messages. Does that mean it ran fine? also, is it ok my solution of putting that line in cron to run every 2 weeks or do you know of a better way?

Kind thanks for the detailed response!

DM

In reply to David Maldonado

Re: Could not open input file: admin/cli/purge_caches

by Ken Task -
Picture of Particularly helpful Moodlers

The 'moodle$' indicates you were already in /path/to/code/moodle directory.    So issuing:

php admin/cli/purge_caches.php would definitly work there.

Cron won't be in /path/to/code/moodle when it executes if the cron job contains a php command, cron won't be able to figure out where moodle/admin/cli/purge_caches.php is located ... moodle code directory NOT in enviromental path of operating system.

So suggest creating a bash shell script in /usr/local/bin/ called pmcache - 'purge moodle cache'.

In the script:

cd /path/to/moodlecode/;

php admin/cli/purgecaches.php

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Could not open input file: admin/cli/purge_caches

by Ken Task -
Picture of Particularly helpful Moodlers

Timed out before I could add ...

point the cron job to the bash shell script in /usr/local/bin/ or any directory for that matter.

I have a preference for storing such scripts in /usr/local/bin/ ...

Oh, yeah.   Been some issues with themes recently ... combo loading ... which means pulling theme libraries off of Yahoo api's ... or something like that ... purging caches in an automated fashion could break stuff like that.

Is there a reason one would set the purging of the caches on auto?

The purge_caches.php  script doesn't have any feedback displayed when it executes.   Bout the only way to check is to list contents of moodledata/cache/ and/or moodledata/localcache where the theme stuff is now stored.   Dang stuff keeps moving arond! :\

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Could not open input file: admin/cli/purge_caches

by David Maldonado -

Good Morning,

Thanks for taking the time Ken.

The reason I want to setup the purge caching to automatic is because I get the " “Coding error detected, it must be fixed by a programmer: Failed to unserialise data from file. Either failed to read, or failed to write. Every month or some times a couple of months go by and I'm ok, but suddently I come in one morning and that coding error is on my screen and no one can login to moodle.


Should I not take the lazy way and just figure out what is causing this? What would be a good approach to debunking the culprit?


Thank you!
DM

In reply to David Maldonado

Re: Could not open input file: admin/cli/purge_caches

by kamesh veerachamy -

Please make sure the below points.

1)Check your config.php from moodle root path.Please make sure the DB details,wwwroot,moodledata path its given values are correct.

2) Check the moodledata path permissions, files -0666 , folders-0777

3) Please recall which plugin you installed latest,  remove that plugin the check.

In reply to kamesh veerachamy

Re: Could not open input file: admin/cli/purge_caches

by David Maldonado -

Thank you Kamesh,


Moodle is up for the time being, I just downloaded a fresh copy of the code. It turns out I was using the wrong syntax on the command per Ken's instructions.


Thank you!
DM