background tasks without "scheduled tasks"

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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
    Greg Bryant Guest

  2. Similar Questions and Discussions

    1. Scheduled tasks
      Hi there, My web app needs to run a schduled task - every hour it needs to scan the DB, find any updates and - if there are updates - send an...
    2. Scheduled tasks . . . again!
      Hi all, I really, really apologize for bringing up this age old problem but I am totally baffled. After having read through SEVERAL forums and...
    3. Scheduled Tasks and SSL
      I cannot get my scheduled tasks to run now that SSL is being used on a production box (Windows 2k, MX 6.1, SunOne web server). They worked fine...
    4. Scheduled Tasks won't run
      is there anyway to change the user which scheduler uses ? there must be ?
    5. "Tuning" small tasks ...
      Hello, it is not really a tuning question I think, but although the instance has been tuned, I sometimes observe strange things like the...
  3. #2

    Default Re: background tasks without "scheduled tasks"

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


    Uzytkownik "Greg Bryant" <bryantgHELLO@yahoo.com> napisal w wiadomosci
    news:Xns944947427D47DbryantgHELLOyahoocom@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

    Chung Leong Guest

  4. #3

    Default Re: background tasks without "scheduled 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_6dnXxQwbiWbkyiRVn-uA@comcast.com:
    > Weird. Did you check in the Control Panel? Make sure the Task
    > Scheduler service is running too.
    >
    >
    > Uzytkownik "Greg Bryant" <bryantgHELLO@yahoo.com> napisal w wiadomosci
    > news:Xns944947427D47DbryantgHELLOyahoocom@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).
    Greg Bryant Guest

  5. #4

    Default Re: background tasks without "scheduled 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 "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.
    Google Mike Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139