+ Reply to Thread
Results 1 to 4 of 4

Thread: Executing background jobs - Permissible or not ?

  1. #1
    academics17 is offline x10Hosting Member academics17 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    3

    Executing background jobs - Permissible or not ?

    I need to run a PhP job in the background. This will collect data and populate a mysql database. When I am doing the same on my desktop machine, I have the luxury of "kill"ing it if it misbehaves but I am not sure whether on x10 -- without shell access -- I could do the same. Again, I do not want to create a runaway program that causes difficulty to others.

    What would be a good way to strategy for this requirement within the constraints of a free x10 account.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Executing background jobs - Permissible or not ?

    You can have non-interactive processes that run as cron jobs. However, the high resource usage (HRU) restriction will still apply. If you're worried about a runaway PHP script, you can use set_time_limit. More generally, you can force a command to exit with:

    Code:
    #!/bin/bash
    
    timeout=30
    if [ $# -gt 0 ]; then
        timeout=$1
    fi
    
    /path/to/binary arg0 arg1 ... argN >$HOME/log/job.log 2>&1 &
    sleep $timeout && kill $! 2>/dev/null
    Replace the "/path/to/binary ... argN" with the command to run, save it as a file in ~/bin and set the cron job command to the file.

    Even more generally, you can use the following script (saved as e.g. "~/bin/timelimit") to run an arbitrary command for a limited length of time. Make sure you escape any shell metacharacters when calling the script so they don't get interpreted before timelimit gets a chance to execute the command.
    Code:
    #!/bin/bash
    
    timeout=30
    if [ $1 -ne 0 2>/dev/null ] ; then
        timeout=$1
        shift
    fi
    eval "$*" &
    sleep $timeout && kill $! 2>/dev/null
    Example usage:

    Code:
    $HOME/bin/timelimit 60 cut -f 1 -d ' ' $HOME/data/activity \| sort -n \| uniq -c \>$HOME/logs/visit_counts
    #or:
    $HOME/bin/timelimit 60 "cut -f 1 -d ' ' $HOME/data/activity | sort -n | uniq -c >$HOME/logs/visit_counts"
    For an example of how you can run multiple, specific commands with a timeout for all, read Alarms, Timeouts and Parallel Processes in Bash
    Last edited by misson; 01-25-2012 at 01:29 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    qchimex1 is offline x10Hosting Member qchimex1 is an unknown quantity at this point
    Join Date
    Feb 2012
    Posts
    1

    Re: Executing background jobs - Permissible or not ?

    academics17 : did you find out how to do this? I have same requirement of running a PHP process in background continuously ( till its killed).

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Executing background jobs - Permissible or not ?

    @qchimex1: you need to pay closer attention when reading, both to my post and the terms of service which you agreed to when you signed up. Both already address your post.
    Last edited by misson; 02-28-2012 at 04:13 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Crons are not executing.
    By daron0382 in forum Free Hosting
    Replies: 1
    Last Post: 04-13-2011, 04:03 PM
  2. International Jobs Program - Earn $ 0.1 - $ 1 per Jobs
    By groove.cell14 in forum Earning Money
    Replies: 3
    Last Post: 10-17-2010, 01:36 AM
  3. Cron Jobs not executing or sending mails
    By markhere in forum Free Hosting
    Replies: 7
    Last Post: 09-05-2010, 02:55 PM
  4. Replies: 1
    Last Post: 05-31-2008, 09:23 PM
  5. Executing SQL Syntax
    By the_king_dollars in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 12-07-2006, 08:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers