background tasks without "scheduled tasks"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Google Mike
    Guest replied
    Re: background tasks without "schedu led tasks"

    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 "LocalSyste m".

    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\SYSTEM 32 directory.
    3. instsrv MyService C:\WINNT\SYSTEM 32\srvany.exe
    4. Regedit. Look for HKEY_LOCAL_MACH INE\Services\Cu rrent 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.PH P - phpsocketserver d
    #
    # chkconfig: - 85 15
    # description: Socket Server is my custom PHP app.
    # processname: phpsocketserver d

    # 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.ph p & >/dev/null
    success "phpsocketserve rd startup"
    echo
    touch /var/lock/subsys/phpsocketserver d
    return 0
    }

    stop() {
    # you'll need to make phpsocketserver killer.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/phpsocketserver dkiller.php & >/dev/null
    success "phpsocketserve rd shutdown"
    echo
    rm -f /var/lock/subsys/phpsocketserver d
    return 0
    }

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

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

    exit $RETVAL
    # once saved in /etc/init.d as phpsocketserver d, 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.

    Leave a comment:


  • Greg Bryant
    Guest replied
    Re: background tasks without "schedu led tasks"

    (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" <chernyshevsky@ hotmail.com> wrote in
    news:o_6dnXxQwb iWbkyiRVn-uA@comcast.com:
    [color=blue]
    > Weird. Did you check in the Control Panel? Make sure the Task
    > Scheduler service is running too.
    >
    >
    > Uzytkownik "Greg Bryant" <bryantgHELLO@y ahoo.com> napisal w wiadomosci
    > news:Xns9449474 27D47DbryantgHE LLOyahoocom@199 .45.49.11...[color=green]
    >>
    >> 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).[/color][/color]

    Leave a comment:


  • Chung Leong
    Guest replied
    Re: background tasks without &quot;schedu led tasks&quot;

    Weird. Did you check in the Control Panel? Make sure the Task Scheduler
    service is running too.


    Uzytkownik "Greg Bryant" <bryantgHELLO@y ahoo.com> napisal w wiadomosci
    news:Xns9449474 27D47DbryantgHE LLOyahoocom@199 .45.49.11...[color=blue]
    > 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[/color]
    overhaul,[color=blue]
    > 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[/color]
    thing[color=blue]
    > 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[/color]


    Leave a comment:


  • Greg Bryant
    Guest started a topic background tasks without "scheduled tasks"

    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
Working...