[FX.php List] Crontab to run php script?

Leo R. Lundgren leo at finalresort.org
Sat Jun 5 16:08:58 MDT 2010


How is that relevant to this picture? I thought we were speaking about how to set up cron and not what framework one would use for things :)


5 jun 2010 kl. 19.54 skrev Gjermund Gusland Thorsen:

> It’s usually better to run pyFileMaker than FX.php when you are to
> work with non-webstuff.
> 
> ggt
> 
> 2010/6/5 Leo R. Lundgren <leo at finalresort.org>:
>> Let me clarify something regarding the private and public seperation I mentioned:
>> 
>> 1) This would mean that if it was up to me, the cron file to be run in your application would be placed somewhere in the private folder, since it shouldn't (I suppose) be accessible from the web.
>> 
>> 2) The reason the cron php file is placed in the public folder in the example below is that it is not me who wrote this application; The author put everything in one folder, which I don't recommend. But that's the reason the example I gave doesn't fit the first paragraph of my ramblings :P
>> 
>> 
>> 5 jun 2010 kl. 11.12 skrev Leo R. Lundgren:
>> 
>>> If there is no specific reason to put it in another place, I suggest just keeping it with the rest of the application, which would presumably be with the rest of the PHP files.
>>> Personally I always seperate stuff into a private (where I keep all the code and resources that shouldnt be directly accessible from the web) and a public folder (equal to the DocumentRoot in apache, where everything visible to the web should be placed).
>>> I do this in order to without further adue be able to use the file system's security instead of having everything in the public folder and then having to rely on web server specific access controls (such as .htaccess or other configuration in Lighttpd/Nginx/IIS).
>>> 
>>> Anyway, where you put the files its mostly subject to detailed technical issues, if any. For example, if you have open_basedir and/or safe_mode set in your PHP configuration and put the file outside that, I'm not sure it would run (though I cannot say for sure if those settings are used similarly when you run the PHP script from the console binary instead of mod_php if that's what you are using normally).
>>> 
>>> Here's an example crontab entry for a maintenance script I have somewhere:
>>> 
>>> 
>>>       * * * * * cd /Library/WebServer/Documents/242285/my.domain.com/public/sms/ && /usr/local/php5/bin/php cron.php 2>&1 >> ../../cron.txt
>>> 
>>> Some explanations:
>>> 
>>>       It runs each minute due to the * * * * *, where a * means "every time" and the positions are minute, hour, day of month, month, day of week. If I were to run it once each hour it would be 0 * * * *, and if I wanted to run it at 3:30 am every working day it'd be "30 3 * * 0,1,2,3,4". Having it run every two hours would be 0 */2 * * *. For more information, do `man 5 crontab` in the terminal and it will explain the format.
>>> 
>>>       To edit or create a crontab file for a specific user when logged in as root (requires root privileges): crontab -eu theUsername
>>>       To edit or create a crontab file as/when logged in a specific user: crontab -e
>>>       To edit or create the crontab file using a specific editor instead of the default which might be `vi`, in this case `nano` instead, prepend EDITOR=theEditorBinaryOrPathToBinary, such as: EDITOR=nano crontab -eu theUsername
>>> 
>>>       The reason I am using absolute paths to everything is that sometimes the environment for the user and processes meant to be run isn't set up like you normallt expect. One can then either set it in the crontab file or if it's mostly about the paths not working, one can just use absolute paths. Whatever works, read more about it in the man pages.
>>> 
>>>       I'm first cd'ing to the place where I would like the script to write its files, if any. In this case the /Library/WebServer/Documents/242285/my.domain.com/public/sms/ folder. This isn't needed to just run the script itself though.
>>> 
>>>       The stuff at the end redirects standard error output (2>) to standard output (&1) and then redirects standard output (>>) to the file ../../cron.txt which effectively becomes /Library/WebServer/Documents/242285/my.domain.com/cron.txt due to the relative nature of the specified path in combination with where the script starts out in the filesystem.
>>> 
>>> Good luck!
>>> 
>>> 
>>> 5 jun 2010 kl. 04.42 skrev Jonathan Schwartz:
>>> 
>>>> Hi Folks,
>>>> 
>>>> I need to create a Crontab in OS X Server to run a php script. The script performs sales order post processing instead of doing it during order entry. This allows sales reps to be more efficient.
>>>> 
>>>> The question is whether I can I leave the script, which calls other scripts, in the existing web folder.  On OS X Server, that is /Library/WebSerber/Documents/TheWebFolder.
>>>> 
>>>> Moving along, I'm struggling with how to create the crontab to call the script.
>>>> 
>>>> Any experienced crontab jockeys out there?
>>>> 
>>>> Jonathan
>>> 
>>> 
>>> 
>>> -|
>>> 
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>> 
>> 
>> 
>> -|
>> 
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



-|



More information about the FX.php_List mailing list