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

background tasks without "scheduled tasks"

P: n/a
I'm doing some work for a company that has an auction site running in
coldfusion. They're not real happy with it, and it needs a major overhaul,
so I'm looking at redoing it, and while I'm at it, might as well move to
PHP (for a variety of reasons - not trying to reopen the PHP -vs- CFM thing
again :).

Anyway, so I'm looking at this system, and there are no "scheduled tasks"
(it's win2kas). How do you write a server app that needs to know when to
make things happen with a cron job? Is there some other technique that I
missed (long running processes with sleep() tend to be prone to error, and
I'm not sure that either cfm or php support that anyway).

Thanks,
Greg
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Weird. Did you check in the Control Panel? Make sure the Task Scheduler
service is running too.
Uzytkownik "Greg Bryant" <br**********@yahoo.com> napisal w wiadomosci
news:Xn**********************************@199.45.4 9.11...
I'm doing some work for a company that has an auction site running in
coldfusion. They're not real happy with it, and it needs a major overhaul, so I'm looking at redoing it, and while I'm at it, might as well move to
PHP (for a variety of reasons - not trying to reopen the PHP -vs- CFM thing again :).

Anyway, so I'm looking at this system, and there are no "scheduled tasks"
(it's win2kas). How do you write a server app that needs to know when to
make things happen with a cron job? Is there some other technique that I
missed (long running processes with sleep() tend to be prone to error, and
I'm not sure that either cfm or php support that anyway).

Thanks,
Greg

Jul 17 '05 #2

P: n/a
(that should have been "with*out* a cron job" in my first note)

I just had a brainwave this morning. I remembered one of the problems
the owner told me about was not sending emails at auction close. They
had assumed (and I followed along) that the cfm script was broken. bzzzt.
I'm betting it's never run.

Task Scheduler is running, no strange messages in the event logs, only
thing odd is FireDaemon service, but I think it's just used to load up
their FTP server.

The more I think about it, the more sure I am that's it. The auction
software they're using was bought several years ago, and they have no
docs for it, so everything's a guess.

Thanks,
Greg

"Chung Leong" <ch***********@hotmail.com> wrote in
news:o_********************@comcast.com:
Weird. Did you check in the Control Panel? Make sure the Task
Scheduler service is running too.
Uzytkownik "Greg Bryant" <br**********@yahoo.com> napisal w wiadomosci
news:Xn**********************************@199.45.4 9.11...

Anyway, so I'm looking at this system, and there are no "scheduled
tasks" (it's win2kas). How do you write a server app that needs to
know when to make things happen with a cron job? Is there some other
technique that I missed (long running processes with sleep() tend to
be prone to error, and I'm not sure that either cfm or php support
that anyway).


Jul 17 '05 #3

P: n/a
Everything you wanted to know about PHP and background tasks on *nix
or W2K, but were afraid to ask...

1) On W2K, you can get Scheduled Tasks if you install it from
Add/Remove Programs, Windows Setup. Then, you have to start the Task
Scheduler service. This is a great way to make something load under an
ID upon login. I don't know what happens when you log out, though --
does it shut down? If it does, then you'll need to have a service.
There's a way to do that. See my next note.
2) On W2K, if you don't want scheduled tasks, but need a service that
remains running even when you log out, and can also be started and
stopped locally or remotely, then you need instsrv.exe and srvany.exe
from the W2K RK (or find it on all-the-web.com or google). The
instsrv.exe is a tool to stick srvany.exe in the registry as a
service. Then, you read srvany.wri (an MS Write file) to find out how
to edit the registry to load anything you want, including a .BAT,
..CMD, .COM, .EXE, .PHP, or virtually any extension where your OS will
automatically execute it. You can run this as any user you want,
including "LocalSystem".

The procedure for the service is:

1. Come up with a service name with no spaces. I'll use MyService for
now.
2. Copy instsrv.exe and srvany.exe to the C:\WINNT\SYSTEM32 directory.
3. instsrv MyService C:\WINNT\SYSTEM32\srvany.exe
4. Regedit. Look for HKEY_LOCAL_MACHINE\Services\Current Control
Set\MyService folder.
5. Where you see Display Name property, set it to anything you want,
and with spaces if you desire. (This change won't be reflected until
you reboot, however.)
6. The rest you'll have to verify from srvany.wri -- going by memory
here:
a. Create a subfolder called Parameters.
b. Create a property (right pane of window) called Application.
c. Set the value of the Application property to the file you want to
launch, including any parameters you want.
7. Open Control Panel, Services, and find your service. Until you
reboot, it will have the old display name (like MyService). Set the
start mode (Automatic, Manual, etc.), Logon User, and other parameters
as you see fit.
8. Reboot and then if you have the service to launch automatically,
it'll be running and you'll see both srvany.exe and your executable
sitting in memory via Task Manager (start, run, taskmgr.exe). You'll
see the new display name in the Services Control Panel. You can start
and stop it like a regular service.

I have used this for various socket servers I've built in VB6, but you
could just as well launch a PHP script with a command like:

php -q mysocketserver.php

If your system is setup a certain way, you might be able to just
specify mysocketserver.php (without the php -q) to make it launch.
Depends on what you did in setting up the .PHP extension.
3) Of course, if you have *nix, then you need something like chron, or
you can build a daemon shell script (acting like a "service") under
/etc/init.d like this (RH9 example):

#!/bin/bash
#
# Startup script for SocketServer.PHP - phpsocketserverd
#
# chkconfig: - 85 15
# description: Socket Server is my custom PHP app.
# processname: phpsocketserverd

# Do not edit chkconfig: - 85 15 above

# Source function library.
.. /etc/rc.d/init.d/functions

# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi

# define vars
RETVAL=0

#
start() {
echo -n $"Starting Custom Socket Server: "
php -q /root/socketserver.php & >/dev/null
success "phpsocketserverd startup"
echo
touch /var/lock/subsys/phpsocketserverd
return 0
}

stop() {
# you'll need to make phpsocketserverkiller.php talk to the socket
server on
# a port to tell it to shut down, or you can use pstree, grep, cut,
and kill to
# find the process ID, parse just the ID, and kill the process.

echo -n $"Stopping Custom Socket Server: "
php -q /root/phpsocketserverdkiller.php & >/dev/null
success "phpsocketserverd shutdown"
echo
rm -f /var/lock/subsys/phpsocketserverd
return 0
}

localstatus() {
if [ -f /var/lock/subsys/phpsocketserverd ]; then
echo "phpsocketserverd started"
else
echo "phpsocketserverd stopped"
fi
RETVAL=0
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
localstatus
;;
restart)
stop
start
;;
*)
echo $"Usage: phpsocketserverd {start|stop|restart|status}"
exit 1
esac

exit $RETVAL
# once saved in /etc/init.d as phpsocketserverd, then chmod'd and
chown'd just
# like the other files there, you can start, stop, reset, and check
the status
# of this "service" from the Services Control Panel in RH9 Linux.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.