How do you tell how much a resources a script uses?

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
I have a script that creates files for a gallery and it write to these files every time the script runs.

How do I tell how much resources the script is using?
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
The easiest way to do this is to write to a file the time that the script starts and the time that it ends, then you can experiment in how to make your PHP scripts more efficient. The resource usage monitor you were probably thinking about would need to be run on the server.
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
would I be able to tell if I ran the script from my computer using XAMMP?
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Yes, you can open task manager and see how much memory/cpu usage spikes up when you run the script. Any other measurement but timing is relative to the servers capabilities, as you would not want to worry about the resource usage of a huge script that doesn't add to the load time. The timing is really all that matters. Here is a nice script that should work for you:

PHP:
//At the start of the script.
$filename = "timings.log";
if (!file_exists($filename)) {
	touch($filename);
}
$timings = fopen($filename,"a");
fwrite($timings,date("g:i:s:u a")."\n\r");

//PHP body...

//At the end of the script
fwrite($timings,date("g:i:s:u a")."\n\r\n\r");
fclose($timings);
 
Top