SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    kill all instances of a script.

    Hi,

    Īn the same vein as another thread I've initiated, I'd like to know if there is way in php to kill all instances of a script.

    How would you kill all the instances of a script say named "endless.php", contaiing an endless loop (while1=1)?

    I know it doesn't make much sense. I'm trying to understand some theoretical points here

    Thanks in advance to those who'll help me.

    Regards,

    -jj.

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to kill it from an outside source? Or from within endless.php?
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If php is running as cgi/fastcgi in your shell execute:
    killall -9 php

    will kill all instances of all scripts.

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Kill it from an outside source.

    Here's the idea:

    kill.php
    PHP Code:
    kill("endless.php"); 
    It's got to be done with php, hence my questionning

  5. #5
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,994
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    PHP has a setting in the php.ini called max_execution_time which determines how long a script has got to be processed, once the time set has been reached it will terminate processing the script.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  6. #6
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script I'm talking about has a set_time_limit(0); Hence the question.

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Location
    New York
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is something for you posted in PHP Manual as User Note:

    gid at gifpaste dot net (18-Dec-2002 12:26)

    For those that want to kill everything matching a certain pattern (ala killall in for linux), try something like this. Note that this is a good idea to do something like this for cross platform compatilibity, instead of executing killall, because killall for other UNIXes does just that, kills EVERYTHING.
    function killall($match) {
    if($match=='') return 'no pattern specified';
    $match = escapeshellarg($match);
    exec("ps x|grep $match|grep -v grep|awk '{print $1}'", $output, $ret);
    if($ret) return 'you need ps, grep, and awk installed for this to work';
    while(list(,$t) = each($output)) {
    if(preg_match('/^([0-9]+)/', $t, $r)) {
    system('kill '. $r[1], $k);
    if(!$k) $killed = 1;
    }
    }
    if($killed) {
    return '';
    } else {
    return "$match: no process killed";
    }
    }
    www.forkaya.com - Web Development, PHP Scripting

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another possibility is to make these scripts continually check with some external resource if they should keep running. Like your other script, have it check a database or check for a file or dir as a flag.


Bookmarks

Posting Permissions

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