Web Hosting Talk







View Full Version : PHP - please help


Bullet
02-17-2002, 08:57 PM
hi

Let's say i got glithy php script. When it runs it eats up all the RAM...
How can i find out where is it located on HDD or at least it's name???
There's no problem with *.cgi or *.exe files - i can see them in "top" or "pstree".
What to do with php scripts???

Please, HELP
:bawling:

Mike the newbie
02-17-2002, 09:48 PM
The name and version of your OS may be helpful.

However, (presuming it is a unix flavor) man locate may be your friend. Give it a try.

Bullet
02-17-2002, 09:55 PM
It's Linux RH 7.2, PHP 4.1.1 and Apache 1.3.23

"top" shows thing like this:
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
4705 apache 11 0 4208 4208 3556 S 0.3 0.4 0:00 httpd

How can i get know the name of the file that initiated this process?

2 Mike the newbie: what to "locate"?

(sorry for my english, i hope U got the idea)

Mike the newbie
02-17-2002, 10:52 PM
Originally posted by Bullet
It's Linux RH 7.2, PHP 4.1.1 and Apache 1.3.23

"top" shows thing like this:
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
4705 apache 11 0 4208 4208 3556 S 0.3 0.4 0:00 httpd

How can i get know the name of the file that initiated this process?

2 Mike the newbie: what to "locate"?...


httpd is the daemon associated with apache. The name of the file that start the process you mentioned is httpd (the last item on the line of the top command).

I don't have my RH Linux server around anymore, so I cannot tell you where the httpd file is located.

Ahmad
02-18-2002, 10:30 AM
Hi,

He means that if you have a CGI script that is using lots of resources (RAM and CPU), you can know about it and its name using top, because it will appear on there.

Now what if that was a PHP file instead? All PHP files are run by httpd processes, so when you do a TOP, the PHP script that is causing the problem will appear with the name 'httpd' in ps. How can you then know which PHP script (among all those php scripts installed on your server) is the one causing all that trouble.

I hope this clarifies the question, I have no answer to it though.

spock
02-18-2002, 10:56 AM
That's an interesting question. You may be able to figure this out by using the Apache mod_status module, which will show what each child is currently serving and the CPU usage.

priyadi
02-18-2002, 07:24 PM
Originally posted by spock
That's an interesting question. You may be able to figure this out by using the Apache mod_status module, which will show what each child is currently serving and the CPU usage.

Yes, but it won't tell you which php file that consume so much resources.

Bullet
02-18-2002, 08:31 PM
What i know for now is.....
I can install PHP the way Perl installed. I mean it doesn't has to be an Apache module. This will give me the ability to trace PHP just like CGI...

So the good thing in using PHP as NOT Apache module is that i can trace files.

What are bad sides?

Any other ideas?

spock
02-18-2002, 08:47 PM
Originally posted by Bullet
I can install PHP the way Perl installed. I mean it doesn't has to be an Apache module.
What are bad sides?


AFAIK, the most significant downside of using PHP in this way is that you lose performance.

Bullet
02-18-2002, 09:09 PM
I cleary understand it.....

But if U got server with at least 50 users and at least 3 of them install glitchy scripts U lose performance 2 times more :-)

For example i got user (still ain't know his name, can't find) with damn glitchy script. It starts, eats ~25% of CPU and ~200Mb of RAM. It never stops himself. In ~10 mins ~5 copies of it are running. Box crashes in ~ 20 mins.
We now running some tool (written in C) that kills them. If things are bad this tool just reboot box while it's not to late...
But i want to find such user....... and then delete them.. slowly.. :-)

spock
02-18-2002, 09:17 PM
Originally posted by Bullet
It starts, eats ~25% of CPU and ~200Mb of RAM.

I can see the problem, and running PHP in CGI mode is probably a good idea for this scenario. That way you'll also be able to enforce resource limits in order to minimize the impact of such scripts. Good luck.

magnafix
02-19-2002, 12:33 AM
Assuming you have mod_status going, just match up the PID of the offending process in 'top' with the output of the status page. Then you know the filename at least. With luck, it'll have a somewhat unique name -- if not, then you're stuck matching up the approximate time of the request with your access_log

Happy trails,