mameha — 2009-02-10T00:28:42-05:00 — #1
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...
dman_2007 — 2009-02-10T00:38:00-05:00 — #2
how do you run the php script? from command line or through a web page request?
mameha — 2009-02-10T00:41:57-05:00 — #3
sorry, it is run through the browser.
crmalibu — 2009-02-10T00:46:33-05:00 — #4
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.
dman_2007 — 2009-02-10T01:09:41-05:00 — #5
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/01/12/running-a-background-process-in-php/
mameha — 2009-02-10T01:19:35-05:00 — #6
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.
crmalibu — 2009-02-10T02:06:22-05:00 — #7
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.
mameha — 2009-02-10T02:38:11-05:00 — #8
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?
crmalibu — 2009-02-10T02:43:29-05:00 — #9
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()
mameha — 2009-02-10T03:03:49-05:00 — #10
thanks i will try to set that up.
kyberfabrikken — 2009-02-10T04:37:06-05:00 — #11
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.