By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,189 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,189 IT Pros & Developers. It's quick & easy.

crond

P: n/a
How do I create a process that will be called periodically to do some task?
This is not necessarily php but not sure where to ask.

Essentially I want to create either a php script or app(C++ would be nice)
to run once a day that will generate a set of images to be used for
captchas.

Any ideas or ideas where I can look for more info?

Thanks,
Jon
Jun 5 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
you mentioned it in the subject of your post - use cron.

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

it's possible to call a php script via cron directly or you call a
small shellscript, that open the php, f. e.

#!/bin/sh

# execute php script
# -q =quiet, suppress the php-header
php -q /home/mysql/script.php

Jun 5 '07 #2

P: n/a
On Jun 5, 7:21 am, Lammi <Lorenz.Lammersd...@gmail.comwrote:
you mentioned it in the subject of your post - use cron.

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

it's possible to call a php script via cron directly or you call a
small shellscript, that open the php, f. e.

#!/bin/sh

# execute php script
# -q =quiet, suppress the php-header
php -q /home/mysql/script.php
if you can use cron cos you are on windows, use cronw instead. You can
also register your script as a service and start that every day (the
service could self-stop after its work is done) then you could use a
line such as
"service name" start
in cron
I dont see a point to registering as a service, but I mention it just
for fun!

Jun 5 '07 #3

P: n/a
shimmyshack wrote:
On Jun 5, 7:21 am, Lammi <Lorenz.Lammersd...@gmail.comwrote:
>you mentioned it in the subject of your post - use cron.

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

it's possible to call a php script via cron directly or you call a
small shellscript, that open the php, f. e.

#!/bin/sh

# execute php script
# -q =quiet, suppress the php-header
php -q /home/mysql/script.php

if you can use cron cos you are on windows, use cronw instead. You can
also register your script as a service and start that every day (the
service could self-stop after its work is done) then you could use a
line such as
"service name" start
in cron
I dont see a point to registering as a service, but I mention it just
for fun!
Or easier yet - just set up a scheduled task in the control panel.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 5 '07 #4

P: n/a

"shimmyshack" <ma********@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
On Jun 5, 7:21 am, Lammi <Lorenz.Lammersd...@gmail.comwrote:
>you mentioned it in the subject of your post - use cron.

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

it's possible to call a php script via cron directly or you call a
small shellscript, that open the php, f. e.

#!/bin/sh

# execute php script
# -q =quiet, suppress the php-header
php -q /home/mysql/script.php

if you can use cron cos you are on windows, use cronw instead. You can
also register your script as a service and start that every day (the
service could self-stop after its work is done) then you could use a
line such as
"service name" start
in cron
I dont see a point to registering as a service, but I mention it just
for fun!
Actually guys, I have no idea how to run a script or anything on the web
host's server but I assume they have this ability? (to schedule maintenance)

I think its a linux platform so I image they have crond or something like
that. There web site forum was down last time I checked so I haven't found
out whats really going on.

Thanks,
Jon
Jun 5 '07 #5

P: n/a
Jon Slaughter wrote:
"shimmyshack" <ma********@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
>On Jun 5, 7:21 am, Lammi <Lorenz.Lammersd...@gmail.comwrote:
>>you mentioned it in the subject of your post - use cron.

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

it's possible to call a php script via cron directly or you call a
small shellscript, that open the php, f. e.

#!/bin/sh

# execute php script
# -q =quiet, suppress the php-header
php -q /home/mysql/script.php
if you can use cron cos you are on windows, use cronw instead. You can
also register your script as a service and start that every day (the
service could self-stop after its work is done) then you could use a
line such as
"service name" start
in cron
I dont see a point to registering as a service, but I mention it just
for fun!

Actually guys, I have no idea how to run a script or anything on the web
host's server but I assume they have this ability? (to schedule maintenance)

I think its a linux platform so I image they have crond or something like
that. There web site forum was down last time I checked so I haven't found
out whats really going on.

Thanks,
Jon

Jon,

You may or may not have the ability. It depends on the permissions the
host gave you. Some allow cron jobs, some don't.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 5 '07 #6

P: n/a
>
You may or may not have the ability. It depends on the permissions the
host gave you. Some allow cron jobs, some don't.
Now is that really the only way to schedule stuff in a linux enviroment? I
mentione dthe crond int eh subject cause thats all I know about.

What I'm trying to get at, is it going to be impossible to schedule stuff if
the host doesn't have it setup to do that? Obviously it can be impossible
but here I mean in general for most web hosts is it a common thing to allow
or deny?

Also is there any way to check for schelduling abilities? I have no shell in
the web host I think... just ftp and http.

oh, wait, I think I do have schelduling abilities... in the control panel
stuff for the site. I'll have to go check and see as I remember seeing that.

Thanks,
Jon
Jun 5 '07 #7

P: n/a
oh, wait, I think I do have schelduling abilities... in the control panel
stuff for the site. I'll have to go check and see as I remember seeing
that.
Yep, I guess they do. Has a way to add cron jobs and just have to give it
the script name.

I assume this is bash stuff? (I haven't done any unix scripting in a very
long time and very little but I assume the other posts give the script that
will work here). I just remember there being several types

Ultimately though I'd like to create a C++ app that will generate the
captchas since it will probably be optimized. I'm not sure how the web hosts
deal with time sharing but I don't want to take to much time. Ultimately I'd
like to generate the captchas in real time when they are needed and apply
random transformations to them instead of pre generating but I think this
might be to slow. (not sure how long it will take to generate one)

I guess I can do some tests and find out though after I get the thing
working.

Thanks,
Jon
Jun 5 '07 #8

P: n/a
Rik
On Tue, 05 Jun 2007 18:14:15 +0200, Jon Slaughter
<Jo***********@Hotmail.comwrote:
>>
You may or may not have the ability. It depends on the permissions the
host gave you. Some allow cron jobs, some don't.

Now is that really the only way to schedule stuff in a linux enviroment?
I
mentione dthe crond int eh subject cause thats all I know about.

What I'm trying to get at, is it going to be impossible to schedule
stuff if
the host doesn't have it setup to do that? Obviously it can be impossible
but here I mean in general for most web hosts is it a common thing to
allow
or deny?

Also is there any way to check for schelduling abilities? I have no
shell in
the web host I think... just ftp and http.

oh, wait, I think I do have schelduling abilities... in the control panel
stuff for the site. I'll have to go check and see as I remember seeing
that.
That's where most hosters that allow it put it indeed. Gives them somewhat
more control then allowing it by shell.

If they don't offer it, you could always put up a page that does the work,
and call that from a computer that does have scheduling enabled. (Possibly
with some safety checks.)

--
Rik Wasmus
Jun 5 '07 #9

P: n/a
Jon Slaughter wrote:
I assume this is bash stuff? (I haven't done any unix scripting in a very
long time and very little but I assume the other posts give the script that
will work here). I just remember there being several types
Cron doesn't specifically require bash scripting.

Cron can be used to launch any executable file at a frequency of up to
once per minute. (Or as infrequent as once every 28 years[1] if need be,
but that seems a bit excessive -- if something needs scheduling that
infrequently, you're better off running it manually.)

These executables could be bash scripts, tcsh scripts, Perl scripts,
compiled C code, or raw machine code written in a hex editor if you
like -- anything that you could run from the command line can run from
cron.

That said, most people do seem to use either Perl or some form of shell
scripting for cron jobs.

____
1. Cron users may not believe this, as cron tabs only allow you to specify
minutes, hours, days and months, so it's not clear how to schedule a job
to happen once every 28 years. Technically, you can't, but you can
approximate it by scheduling the job to happen on Sunday 29th February, a
date which only occurs (on average) every 28 years, because of leap years
and the fact that there isn't an integer number of weeks in each year.
Under normal usage, the longest time between cron jobs is 1 year.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 102 days, 1:16.]

URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
Jun 5 '07 #10

P: n/a
Jon Slaughter wrote:
Now is that really the only way to schedule stuff in a linux enviroment?
Cron? No -- there is also "at", but that's more suited towards scheduling a
one-off event in the future.

Or you could write a system service that sleeps for X seconds, wakes up,
does its job and then sleeps again.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 102 days, 1:25.]

URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
Jun 5 '07 #11

P: n/a
On Jun 5, 6:43 pm, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
Jon Slaughter wrote:
Now is that really the only way to schedule stuff in a linux enviroment?

Cron? No -- there is also "at", but that's more suited towards scheduling a
one-off event in the future.

Or you could write a system service that sleeps for X seconds, wakes up,
does its job and then sleeps again.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 102 days, 1:25.]

URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
you could also write a php script that is behind some protection,
which a cron on a machine you do have access to executes.
http://server.com/doit/job63.php?log=secure_email or whatever.

Jun 5 '07 #12

P: n/a

"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:un************@ophelia.g5n.co.uk...
Jon Slaughter wrote:
>I assume this is bash stuff? (I haven't done any unix scripting in a very
long time and very little but I assume the other posts give the script
that
will work here). I just remember there being several types

Cron doesn't specifically require bash scripting.

Cron can be used to launch any executable file at a frequency of up to
once per minute. (Or as infrequent as once every 28 years[1] if need be,
but that seems a bit excessive -- if something needs scheduling that
infrequently, you're better off running it manually.)

These executables could be bash scripts, tcsh scripts, Perl scripts,
compiled C code, or raw machine code written in a hex editor if you
like -- anything that you could run from the command line can run from
cron.

That said, most people do seem to use either Perl or some form of shell
scripting for cron jobs.
Thanks... I'll try to do some more research on it and see what I come up
with... on what to do. I like the idea of using php but I think it won't be
fast enough so I'll look into doing it in C++ and then figure out how to run
it(since I'm on a windows machine I'll have to compile it for linux somehow)

Jon
Jun 5 '07 #13

P: n/a
On Jun 5, 9:34 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
"Toby A Inkster" <usenet200...@tobyinkster.co.ukwrote in messagenews:un************@ophelia.g5n.co.uk...
Jon Slaughter wrote:
I assume this is bash stuff? (I haven't done any unix scripting in a very
long time and very little but I assume the other posts give the script
that
will work here). I just remember there being several types
Cron doesn't specifically require bash scripting.
Cron can be used to launch any executable file at a frequency of up to
once per minute. (Or as infrequent as once every 28 years[1] if need be,
but that seems a bit excessive -- if something needs scheduling that
infrequently, you're better off running it manually.)
These executables could be bash scripts, tcsh scripts, Perl scripts,
compiled C code, or raw machine code written in a hex editor if you
like -- anything that you could run from the command line can run from
cron.
That said, most people do seem to use either Perl or some form of shell
scripting for cron jobs.

Thanks... I'll try to do some more research on it and see what I come up
with... on what to do. I like the idea of using php but I think it won't be
fast enough so I'll look into doing it in C++ and then figure out how to run
it(since I'm on a windows machine I'll have to compile it for linux somehow)

Jon
php offloads some of its work onto c libraries anyway, so unless you
have a specific task in mind that php does not offload, you might not
find too much diff in perf, my $0.02

Jun 6 '07 #14

P: n/a
Jon Slaughter wrote:
>You may or may not have the ability. It depends on the permissions the
host gave you. Some allow cron jobs, some don't.

Now is that really the only way to schedule stuff in a linux enviroment? I
mentione dthe crond int eh subject cause thats all I know about.

What I'm trying to get at, is it going to be impossible to schedule stuff if
the host doesn't have it setup to do that? Obviously it can be impossible
but here I mean in general for most web hosts is it a common thing to allow
or deny?

Also is there any way to check for schelduling abilities? I have no shell in
the web host I think... just ftp and http.

oh, wait, I think I do have schelduling abilities... in the control panel
stuff for the site. I'll have to go check and see as I remember seeing that.

Thanks,
Jon

As I said - it's all up to the host. Some disable it because abuse can
affect system performance.

And yes, that is the scheduler for Linux. You can probably find some
other programs which emulate it, but cron is built into the system and
works the best. And if they disabled cron, chances are there is a
reason and they would be upset if you tried to bypass it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 6 '07 #15

P: n/a
On 5 Jun., 16:13, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
"shimmyshack" <matt.fa...@gmail.comwrote in message

news:11**********************@p77g2000hsh.googlegr oups.com...
On Jun 5, 7:21 am,Lammi<Lorenz.Lammersd...@gmail.comwrote:
you mentioned it in the subject of your post - use cron.
>http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
it's possible to call a php script via cron directly or you call a
small shellscript, that open the php, f. e.
#!/bin/sh
# execute php script
# -q =quiet, suppress the php-header
php -q /home/mysql/script.php
if you can use cron cos you are on windows, use cronw instead. You can
also register your script as a service and start that every day (the
service could self-stop after its work is done) then you could use a
line such as
"service name" start
in cron
I dont see a point to registering as a service, but I mention it just
for fun!

Actually guys, I have no idea how to run a script or anything on the web
host's server but I assume they have this ability? (to schedule maintenance)

I think its a linux platform so I image they have crond or something like
that. There web site forum was down last time I checked so I haven't found
out whats really going on.

Thanks,
Jon
oh it's a hosted server? ask your hosting provider if cronjobs are
possible. if not (or if you don't wanna ask :-) ), try
http://www.cronjob.de/ f. e. (i'm sure there are similar services in
english).

Jun 7 '07 #16

P: n/a
At Tue, 05 Jun 2007 03:32:30 +0000, Jon Slaughter let h(is|er) monkeys
type:
How do I create a process that will be called periodically to do some task?
This is not necessarily php but not sure where to ask.

Essentially I want to create either a php script or app(C++ would be nice)
to run once a day that will generate a set of images to be used for
captchas.

Any ideas or ideas where I can look for more info?

Thanks,
Jon
You could have your captcha-using script check the number of times your
current set of captchas has been 'used' or subtract the time you last
created captcha images from the current time and start the regeneration of
a new batch instead of having to use cron or at.

In practice, I would only worry about overtaxing the server if you have a
massive number of visits each day. The imagefunction set provided by gd is
pretty well opimised, your own C/C++ program might have a challenge trying
to beat it.

I've yet to see the first problem on a site I oversee creating captchas on
the fly. Even on relatively low-end shared environments.

I think you may be worrying about something that may never be a real
problem here.
--
Schraalhans Keukenmeester - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 10 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.