SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to stop a php script from command prompt?

    I am running a PHP script and it takes a long time to execute (parsing huge CSV file).

    How can I stop the script?

    It seems from command prompt you can run:
    > kill $pid

    But I do not know how to find out the pid...

  2. #2
    SitePoint Addict
    Join Date
    Sep 2007
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do you run the php script? from command line or through a web page request?

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, it is run through the browser.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could use the ps command on linux to find the pid.
    maybe take a look at pkill, or combine ps with grep

    edit, oh it through the browser. unless php is run as a cgi, I dont think that will work.

  5. #5
    SitePoint Addict
    Join Date
    Sep 2007
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, can't kill the script unless it was executed as cgi process or from command line. On the other hand, you can run the csv parsing script as a background process, see this : http://nsaunders.wordpress.com/2007/...rocess-in-php/

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually running from command prompt (Im on Win2003) would be preferable, however in the past I found that I got permission problems when doing that. I was unable to write to files using PHP, even though it worked fine when run through the browser.

    I tried to give the write permissions on the file to php-cgi but couldn't figure out how to do it.

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You sure you had permission problems, and not filepath problems? Keep in mind when running php through its CLI, relative filepaths may not work like you think.

  8. #8
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont remember but I just know that it stopped working when it came to writing to a file.

    Why would relative paths stop working?

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because relative filepaths are relative to php's current working directory. The current working directory is not the same directory as where the script lives when run via the cli, unlike the typical webserver enviornment.

    You can use absolute filepaths, or chdir()

    http://www.php.net/features.commandline

  10. #10
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks i will try to set that up.

  11. #11
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mameha View Post
    I dont remember but I just know that it stopped working when it came to writing to a file.
    When PHP run through Apache, the unix user is that of Apache. Eg. www or something similar. When you run a script from the command line, it is run as the current user. On unix systems, files have three types of permissions; user, group and global. Each of these roles can have read, write or execute rights. If you create a file under one user and set the permissions so that other users can access them, well then other users can't access them. You can solve it by putting both users in the same group, set the group ownership to this for the files that need to be shared and finally set group permissions to the same as user permissions (read+write for files and read+write+execute for directories).

    Oh, and if you have open_basedir or safe_mode turned on for PHP, things gets a bit more complicated.


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
  •