473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

background tasks without "scheduled tasks"

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
3 8565
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
(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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Codemonkey | last post by:
Hi, I am writing an App in .Net that involves some scheduling of tasks. I was wondering if anybody has come accross any components or examples of how to implement a schedule manager like the one...
1
by: Dave_NH | last post by:
I would like my VB application to set some specific values in the "Result" code so that when we check the "Last Result" column in Scheduled Tasks we'll see that information. Suggestions?
0
by: johannes | last post by:
there are much apps wich have a control like file and folder tasks in the explorer. id like to have such a control for navigation on my own app where can i find it??
14
by: RDI | last post by:
I'm in the process of wiritng a custom AutoResponder that will run on a spare PC. If I don't write it as an actual "Service" but just a program that starts via the startup folder, will that use...
1
by: Rune Jacobsen | last post by:
Hi, I've been trying to figure this one out, but my experience just doesn't have what it takes... :| I am writing an application that reads an XML file and displays the contents in various...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.