Re: [PHP] PHP + Cron jobs
Waynn Lue wrote: > Right, and I am, so I stayed away from that solution. My next > attempt was to specify /usr/local/bin/php in the cron job, but that > led to a problem because of the include paths. Now that I specific > the full path, evidently the include path no longer is relative to the > directory that's being executed from, and so it fails to execute. One > solution is to also include the executing directory in the php script > itself, I assume, but is there any better solution than that? > I would take a look at your core problem - why do you have php executables in both /usr and /usr/local? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
On Mon, Sep 29, 2008 at 9:34 AM, Richard Lynch <[EMAIL PROTECTED]> wrote: > If you are running PHP as CGI, replacing the CGI with CLI could be > problematic down the road... > > Right, and I am, so I stayed away from that solution. My next attempt was to specify /usr/local/bin/php in the cron job, but that led to a problem because of the include paths. Now that I specific the full path, evidently the include path no longer is relative to the directory that's being executed from, and so it fails to execute. One solution is to also include the executing directory in the php script itself, I assume, but is there any better solution than that? If not, I went ahead with Richard's suggestion to use -q. Assuming a Google search is correct (since man php and php -help don't mention -q), that just suppresses the HTML headers from being sent? Thanks again, Waynn
Re: [PHP] PHP + Cron jobs
On Mon, Sep 29, 2008 at 11:59 AM, Nathan Rixham <[EMAIL PROTECTED]> wrote: > Shawn McKenzie wrote: >> >> Shawn McKenzie wrote: >>> >>> Waynn Lue wrote: Yup, you're completely right. I checked the cronjob and got this: PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle Turns out there's /usr/bin/php, which is the cgi version, and /usr/local/bin/php, which is the cli version. So I see three possiblities. 1. Change the shebang on the php script itself, 2. change the crontab to reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the 3rd, but does that cause problems for me in my actual web pages? Thanks, Waynn >>> Depends upon whether your webserver is using the PHP CGI binary or the >>> apache module. I thought common convention was that the CGI was named >>> php-cgi? >>> >>> I would rename '/usr/bin/php' to '/usr/bin/php-cgi', grep your web >>> server conf file(s) for /usr/bin/php and if found then change it to >>> /usr/bin/php-cgi. >>> >>> -Shawn >>> >> Along with that, I would opt for always using the full path in the cron >> job. >> >> -Shawn > > see I don't use cron; I run small scripts from the command line that fork > then run forever on a while loop with a sleep.. so: > > worker.php > include '/path/to/maininclude.php'; > > $pid=pcntl_fork(); > if(!$pid) { > while(1) { >$work = new work_object; >if( $job = $work-getJobs->('thisjob') ) { > // i have something to do, and doing it here >} else { > sleep(10); >} > } > } else { > echo "\ndaemon launcher done id $pid\n"; > } > ?> > > or you can run say 10 versions at the same time for things where > multi-process helps (scrapers, whois checks etc) > > controller.php > include '/path/to/maininclude.php'; > > for($icount=0;$icount<11;$icount++) { >include './worker.php'; //spawn 10 workers > } > ?> > > just my preference :) > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Just out of curiosity, how's your worker keep track of jobs? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP + Cron jobs
If you are running PHP as CGI, replacing the CGI with CLI could be problematic down the road... From: Waynn Lue [mailto:[EMAIL PROTECTED] Sent: Sunday, September 28, 2008 6:12 AM To: Richard Lynch Cc: Per Jessen; php-general@lists.php.net Subject: Re: [PHP] PHP + Cron jobs Yup, you're completely right. I checked the cronjob and got this: PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle Turns out there's /usr/bin/php, which is the cgi version, and /usr/local/bin/php, which is the cli version. So I see three possiblities. 1. Change the shebang on the php script itself, 2. change the crontab to reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the 3rd, but does that cause problems for me in my actual web pages? Thanks, Waynn ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214
Re: [PHP] PHP + Cron jobs
Shawn McKenzie wrote: Shawn McKenzie wrote: Waynn Lue wrote: Yup, you're completely right. I checked the cronjob and got this: PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle Turns out there's /usr/bin/php, which is the cgi version, and /usr/local/bin/php, which is the cli version. So I see three possiblities. 1. Change the shebang on the php script itself, 2. change the crontab to reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the 3rd, but does that cause problems for me in my actual web pages? Thanks, Waynn Depends upon whether your webserver is using the PHP CGI binary or the apache module. I thought common convention was that the CGI was named php-cgi? I would rename '/usr/bin/php' to '/usr/bin/php-cgi', grep your web server conf file(s) for /usr/bin/php and if found then change it to /usr/bin/php-cgi. -Shawn Along with that, I would opt for always using the full path in the cron job. -Shawn see I don't use cron; I run small scripts from the command line that fork then run forever on a while loop with a sleep.. so: worker.php ('thisjob') ) { // i have something to do, and doing it here } else { sleep(10); } } } else { echo "\ndaemon launcher done id $pid\n"; } ?> or you can run say 10 versions at the same time for things where multi-process helps (scrapers, whois checks etc) controller.php just my preference :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
Waynn Lue wrote: > Yup, you're completely right. I checked the cronjob and got this: > > PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) > Copyright (c) 1997-2008 The PHP Group > Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies >with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle > > Turns out there's /usr/bin/php, which is the cgi version, and > /usr/local/bin/php, which is the cli version. So I see three possiblities. > 1. Change the shebang on the php script itself, 2. change the crontab to > reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the > 3rd, but does that cause problems for me in my actual web pages? > > Thanks, > Waynn > Depends upon whether your webserver is using the PHP CGI binary or the apache module. I thought common convention was that the CGI was named php-cgi? I would rename '/usr/bin/php' to '/usr/bin/php-cgi', grep your web server conf file(s) for /usr/bin/php and if found then change it to /usr/bin/php-cgi. -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
Shawn McKenzie wrote: > Waynn Lue wrote: >> Yup, you're completely right. I checked the cronjob and got this: >> >> PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) >> Copyright (c) 1997-2008 The PHP Group >> Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies >>with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle >> >> Turns out there's /usr/bin/php, which is the cgi version, and >> /usr/local/bin/php, which is the cli version. So I see three possiblities. >> 1. Change the shebang on the php script itself, 2. change the crontab to >> reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the >> 3rd, but does that cause problems for me in my actual web pages? >> >> Thanks, >> Waynn >> > Depends upon whether your webserver is using the PHP CGI binary or the > apache module. I thought common convention was that the CGI was named > php-cgi? > > I would rename '/usr/bin/php' to '/usr/bin/php-cgi', grep your web > server conf file(s) for /usr/bin/php and if found then change it to > /usr/bin/php-cgi. > > -Shawn > Along with that, I would opt for always using the full path in the cron job. -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
Yup, you're completely right. I checked the cronjob and got this: PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle Turns out there's /usr/bin/php, which is the cgi version, and /usr/local/bin/php, which is the cli version. So I see three possiblities. 1. Change the shebang on the php script itself, 2. change the crontab to reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the 3rd, but does that cause problems for me in my actual web pages? Thanks, Waynn
RE: [PHP] PHP + Cron jobs
___ O/H Waynn Lue ??: Perhaps this would do the job much better. 12 6 * * * php -f /home/foo/temp.php Probably no different, unless the new-fangled -f implies -q, and he's running the new version of PHP, which I doubt. Also consider an alternative solution. Add this on the first line of the php script: #! /usr/bin/php This will work if that is where his CLI php lives. If that's his CGI php that the cron is finding, and his shell PHP is something else, it won't change a thing. ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP + Cron jobs
From: Waynn Lue [EMAIL PROTECTED] Sent: Saturday, September 27, 2008 6:04 AM To: Per Jessen Cc: php-general@lists.php.net Subject: Re: [PHP] PHP + Cron jobs > > > This is something that I've noticed for awhile, but last post to this > > mailing list reminded me that someone probably already knows how to > > work > > around this! I have a cron job that looks something like > > > > 12 6 * * * php /home/foo/temp.php > > > > But even if temp.php doesn't output anything, I still get emails from > > the crontab that consist of > > > > "Content-type: text/html" > > > > I assume this is happening because it's interpreting as a web page or > > some such. > > Somehow your /home/foo/temp.php isn't running with the correct PHP > interpreter. > > > Is there a better way to set the crontab so I don't get that > > output? > > You can always use MAILTO= to direct any output from a cronjob. > I actually am using MAILTO, and that's where the problem is. A cronjob only mails when there actually is output, which I'm fine with. In fact, when I run php temp.php from the command line, I don't get any output. But when it's part of the cronjob, there's that content-type output, which triggers mail to me. You mentioned a correct php interpreter above. Should I instead be running php through some other way or with a specific flag? cron does NOT NOT NOT run with the same user/shell as "you" from command line. You have TWO different versions of PHP running on your system. You are running one of them (the newer one). cron is running the older one, almost for sure. Do this from command line: which php Now do this: * * * * * which php Be ready to comment that cron job out as soon as you get the email (and several more) It runs every minute. :-) But you'll find that cron ain't running the same "which php" as you are. TIP: cron jobs should ALWAYS have the FULL path to all files, binaries, inputs, and everything else if you expect it to do what you think it is doing. ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP + Cron jobs
You are using the old school PHP CGI as if it were PHP CLI. Upgrade and use PHP CLI. Or just add -q to the args: 12 6 * * * php -q /home/foo/temp.php php -h will show you the version and nature (CLI/CGI) of PHP you are running, as well as the args and what they do, in rather terse format. From: Waynn Lue [EMAIL PROTECTED] Sent: Saturday, September 27, 2008 4:21 AM To: PHP General list Subject: [PHP] PHP + Cron jobs This is something that I've noticed for awhile, but last post to this mailing list reminded me that someone probably already knows how to work around this! I have a cron job that looks something like 12 6 * * * php /home/foo/temp.php But even if temp.php doesn't output anything, I still get emails from the crontab that consist of "Content-type: text/html" I assume this is happening because it's interpreting as a web page or some such. Is there a better way to set the crontab so I don't get that output? Thanks, Waynn ___ The information in this email or in any file attached hereto is intended only for the personal and confiden- tial use of the individual or entity to which it is addressed and may contain information that is propri- etary and confidential. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communica- tion is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email trans- mission cannot be guaranteed to be secure or error- free. P6070214 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
O/H Waynn Lue ??: This is something that I've noticed for awhile, but last post to this mailing list reminded me that someone probably already knows how to work around this! I have a cron job that looks something like 12 6 * * * php /home/foo/temp.php But even if temp.php doesn't output anything, I still get emails from the crontab that consist of "Content-type: text/html" I assume this is happening because it's interpreting as a web page or some such. Is there a better way to set the crontab so I don't get that output? Thanks, Waynn Perhaps this would do the job much better. 12 6 * * * php -f /home/foo/temp.php Also consider an alternative solution. Add this on the first line of the php script: #! /usr/bin/php And make it executable and then put into cron this: 12 6 * * * /home/foo/temp.php This is if it is an execution problem. In case you have defined MAILTO directive in the crontab then anything that is executed by cron will mail you the results. This comes from crons man page: If MAILTO is defined (and non-empty), mail is sent to the user so named. If MAILTO is defined but empty (MAILTO=""), no mail will be sent. Otherwise mail is sent to the owner of the crontab. By default, cron will send mail using the mail Content-Type: header of text/plain with the charset= parameter set to the charmap / codeset of the locale in which crond(8) is started up -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
Waynn Lue wrote: > Hm looks like it's CLI. > > $ php -v > PHP 5.2.6 (cli) (built: Aug 11 2008 13:36:00) > Copyright (c) 1997-2008 The PHP Group > Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies > with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle Yep, looks good - check that your cron script is also running with that interpreter. I can't really think of why it wouldn't be, but ... /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
Hm looks like it's CLI. $ php -v PHP 5.2.6 (cli) (built: Aug 11 2008 13:36:00) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle
Re: [PHP] PHP + Cron jobs
Waynn Lue wrote: > I actually am using MAILTO, and that's where the problem is. A > cronjob only mails when there actually is output, which I'm fine with. > In fact, when I run php temp.php from the command line, I don't get > any output. But when it's part of the cronjob, there's that > content-type output, which triggers mail to me. > > You mentioned a correct php interpreter above. Should I instead be > running php through some other way or with a specific flag? Check what 'php -v' says when you run it from the command-line - it shuold be something like this: php -v PHP 5.2.4 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 22 2007 02:01:31) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies I suspect yours might be saying 'cgi' instead of 'cli' ? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + Cron jobs
> > > This is something that I've noticed for awhile, but last post to this > > mailing list reminded me that someone probably already knows how to > > work > > around this! I have a cron job that looks something like > > > > 12 6 * * * php /home/foo/temp.php > > > > But even if temp.php doesn't output anything, I still get emails from > > the crontab that consist of > > > > "Content-type: text/html" > > > > I assume this is happening because it's interpreting as a web page or > > some such. > > Somehow your /home/foo/temp.php isn't running with the correct PHP > interpreter. > > > Is there a better way to set the crontab so I don't get that > > output? > > You can always use MAILTO= to direct any output from a cronjob. > I actually am using MAILTO, and that's where the problem is. A cronjob only mails when there actually is output, which I'm fine with. In fact, when I run php temp.php from the command line, I don't get any output. But when it's part of the cronjob, there's that content-type output, which triggers mail to me. You mentioned a correct php interpreter above. Should I instead be running php through some other way or with a specific flag? Waynn
Re: [PHP] PHP + Cron jobs
Waynn Lue wrote: > This is something that I've noticed for awhile, but last post to this > mailing list reminded me that someone probably already knows how to > work > around this! I have a cron job that looks something like > > 12 6 * * * php /home/foo/temp.php > > But even if temp.php doesn't output anything, I still get emails from > the crontab that consist of > > "Content-type: text/html" > > I assume this is happening because it's interpreting as a web page or > some such. Somehow your /home/foo/temp.php isn't running with the correct PHP interpreter. > Is there a better way to set the crontab so I don't get that > output? You can always use MAILTO= to direct any output from a cronjob. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP + Cron jobs
This is something that I've noticed for awhile, but last post to this mailing list reminded me that someone probably already knows how to work around this! I have a cron job that looks something like 12 6 * * * php /home/foo/temp.php But even if temp.php doesn't output anything, I still get emails from the crontab that consist of "Content-type: text/html" I assume this is happening because it's interpreting as a web page or some such. Is there a better way to set the crontab so I don't get that output? Thanks, Waynn
Re: [PHP] PHP Cron jobs
"James Mclean" <[EMAIL PROTECTED]> wrote... > i do not have access to the cron system on my server, but > would like to write a script that does some general housekeeping > on my database, and various other things like removing old users, > sending some newsletters etc... What about putting the script in a regular PHP web page. Then you can call up that page from any machine on the planet and the housekeeping functions will be performed right then. So you could set up a cron job (or whatever) on a machine you _do_ have admin access to, to simply call up the housekeeping page on a regular basis. And you could use some basic authentication to make sure the general public does not call up this page if that is important to you, e.g. check the client IP address. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] PHP Cron jobs
On Sat, 27 Jan 2001 18:05:08 +1030, "James Mclean" <[EMAIL PROTECTED]> wrote: >i do not have access to the cron system on my server >The Sysadmin for the server is absolutly useless, so getting him to submit a >cron job is no good. >any ideas?? My idea: We provide user cron access with your shell account. Apache, PHP and MySQL hosting near the major Chicago NAP. Send me an email and I can give you a test account. :-) Egan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] PHP Cron jobs
The best way really is a cron job ... maybe you need a new ISP or a new sysadmin. Mick > What would be the best way of getting the script to run on a timed basis, > ideally the times and frequency of the script running defined in either the > script its self, or another script. > The Sysadmin for the server is absolutly useless, so getting him to submit a > cron job is no good. > any ideas?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] PHP Cron jobs
List, i do not have access to the cron system on my server, but would like to write a script that does some general housekeeping on my database, and various other things like removing old users, sending some newsletters etc... What would be the best way of getting the script to run on a timed basis, ideally the times and frequency of the script running defined in either the script its self, or another script. The Sysadmin for the server is absolutly useless, so getting him to submit a cron job is no good. any ideas?? TIA jamesmc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]