Welcome Guest, Not a member yet? Register   Sign In
Cron Execution Problem
#1

[eluser]PV-Patrick[/eluser]
I am having a problem with executing a cron script via the first method outlined here: http://codeigniter.com/wiki/Category:Adv...ronScript/

I have gotten everything to work except for 1 thing, the actual execution within cron or even on the command line.

Essientially, the main problem I haven't been able to solve is that everything works fine if I am in the same directory as my cron script file. If I am let's say just in /home and I try and run the file... php /home/user/script.php - it's won't work, but if I am in /home/user/script.php - it works fine. I have tried permissions and ownership, etc.. I am sure it will end up being something rather simple.
#2

[eluser]electromute[/eluser]
Are you getting any feedback/error messages when you try and run the command from /home? I'm assuming you are running this via command line to test it. Is php in your path correctly?
#3

[eluser]PV-Patrick[/eluser]
I am not receiving any errors... the script resides in /home/site/script/script.php - When I run:
sudo -u nobody php /home/site/script/script.php - It does nothing, no errors. When I am in the directory: /home/site/script and I run the command: sudo -u nobody php script.php - It works just fine.
#4

[eluser]electromute[/eluser]
Nothing is jumping out at me, but here are a few things I'd look at:

1. Check the PHP error logs and see if anything is getting logged. Double check your php.ini file to make sure logging and error levels are set the way you want. You may be generating an error and it's getting silently logged.

2. Try doing the same thing with a simple hello world script (if you haven't done so) to make sure the problem is not a code problem. Simply do:

Code:
<?
echo "hello world";
?>

3. Check your path to PHP. If you put it in your script.php file, make sure it's correct. I use MAMP, so my script.php has an initial line of:

Code:
#!/Applications/MAMP/bin/php5/bin/php

Having that set, I can simply run the script like so:

Code:
% /path/to/script/script.php

OR, you can make sure the path to your PHP bin is added to your .bash_profile (I use bash, but there are similar config files for your chosen shell). I've added the following line to mine:

Code:
export PATH=/Applications/MAMP/bin/php5/bin:$PATH

with the above example, no matter where I am, I can run the command:
Code:
% php /path/to/script/script.php

Hope that helps. If it ends up being something else, please post, I'd be curious to see what was up.
#5

[eluser]PV-Patrick[/eluser]
Thank you very much for the effort in help electromute! Smile

I finally cleared my head and started stepping through the process and eventually found the issue. And I was right, it was STUPID!

This piece of code is what did it.
Code:
if($_SERVER['SCRIPT_FILENAME'] != 'clean_cache.php')
  exit;

I needed to have the FULL path specified for that, not just the file name. haha. Anyways, for anyone else who has my problem, that was the solution.

Thanks again Electromute!
#6

[eluser]electromute[/eluser]
Haha, well I did something equally as stupid in my code yesterday as well. Must be too much eggnog. Good luck with your app!

--ingrid
#7

[eluser]PV-Patrick[/eluser]
I apologize for bringing up an old thread but I ran into a problem as I was trying to get it working and I found the solution but now I am looking for an answer as to why and if it really matters.

The problem was everything was working except the cron_script.php was NOT calling the controller/method automatically. It would work from command line but it would not work via cron execution.

So, I randomly tried changing the following value from
Code:
$config['uri_protocol']    = "AUTO";
to
Code:
$config['uri_protocol']    = "PATH_INFO";

...and thus it works like it should now. :roll:

Is there an advantage or disadvantage to setting it to PATH_INFO from AUTO? Everything on the site seems to be working fine as far as I can tell however I was wondering if anyone could explain that value to me a little more in-depth, thank you!
#8

[eluser]sophistry[/eluser]
AUTO and PATH_INFO refer to two of the many elements of PHP's native $_SERVER global. by setting the config you are telling CI which one of them to use in its internal URL construction. most of the time AUTO will work, but sometimes you need to tell it to use a specific element of the $_SERVER global so that your scripts work.

to understand it better, dive into the CI code and find the spot where the uri_protocol config item is set. that will give you an idea of the heuristic the CI devs use for AUTO. then, to understand why AUTO doesn't work for your set up, just do a var_export($_SERVER) in your controller and you'll see how the various elements are different.

it's not that the CI devs did anything wrong, it's that they tried to cover most common scenarios and i think CLI and/or cron job context was not part of "most common scenarios."

cheers.




Theme © iAndrew 2016 - Forum software by © MyBB