Welcome, Guest. [ Log In ]
Question   Why do I only see php.cgi in my resource report?
Search KBase

Top 3 in this Area:
1. What are CPU minutes?
2. Why do I only see php.cgi in my resource report?
3. My account was moved to an evaluation server!

Why do I only see php.cgi in my resource report?
If you run a lot of PHP scripts, then the reports in /home/user/resources/ may show only "php.cgi" instead of the proper script. This is because of the way we run php scripts on the web server.

To fix this, try the following workaround:

All steps below are required for this to work

1) Change the permissions of all your php scripts to be 755. For example:

chmod 755 script.php

You can do all your files at once with the following find command:

find /home/your username/ \( -name "*.php[34]" -or -name "*.php" \) -exec chmod a+x {} \;

Note that this is performed by our system every morning on your machine, so you probably don't have to do this step for existing scripts.

2) For each of your domains, add the following line to your .htaccess:

AddHandler cgi-script .php .php3 .php4

If you don't already have an .htaccess, just create a file named:

/home/your username/mydomain.com/.htaccess

and put the line above in that file. Make sure the permissions are set to 644 for your .htaccess file.

4) Also, please add in the following line at the top of every php script you have:


This will tell your scripts to use the correct php interpreter.

5) Change your domains to not run PHP as CGI here. From the webpanel,
click on:
Domains > Web
Then next to each of your domains, click on "Edit". Uncheck the box titled "Run PHP as CGI" and click "Save Web Service" at the bottom.
NOTE: Some third party software will break during this transition. Because of that, we've made sure that your changes will go live within 2 - 10 minutes after you click "Save Web Service". If things break, you can quickly change it back!

4) If you have any custom .htaccess files, you may have to edit them. You'll have to do this for every domain that you have setup with a custom .htaccess file. You might have something like this:
AddHandler application/x-httpd-php
If you had the line above, you would need to remove it. In fact, you might have something else in your .htaccess file that causes your PHP scripts to be run as a cgi. If that's the case, you'll need to remove it as well.

If the approach above is not feasible for you, the best work-around for this is to examine your stats page and look for the php scripts with the most requests.

Last updated: Dec 18, 2005.

User Post (2005-12-20 19:26:49 by bradc)
As a caveat, any site running PHP5 w/ classes built for OOP support will break if you turn off PHP5 to be able to do this step - Anyone have any other suggestions?
User Post (2005-12-16 20:22:53 by johnengler)
step #2 kills one of my sites. Is is absolutely neccessary?
User Post (2005-12-07 16:40:21 by kallahar)
This solution didn't work for me, so I wrote this function. On my site I include a PrintHeader() and PrintFooter() function on every page, so it's a convenient place to put it. Otherwise you'll need this code on every page.

1) Put this at the very top of the script (in the header): global $start_time; $start_time = microtime();
2) At the very end (in the footer) put this:
global $start_time;
$ra_start = explode(' ', $start_time);
$ra_end = explode(' ', microtime());
$cpu_time = ($ra_end[1]+$ra_end[0]) - ($ra_start[1]+$ra_start[0]);
$f = fopen('/home/kallahar/cpu_usage.log', 'a', 1);
// time seconds request by_ip
fwrite($f, date('m-d-Y H:m:s')."\t".$cpu_time."\t".$_SERVER['SERVER_NAME']."\t".$_SERVER['PHP_SELF']."\ t".$_SERVER['REMOTE_ADDR']."\n");
3) create a file called cpu_usage.log in the root directory (the one in the fopen command)

This creates a tab delimited log for every page you include this on with microsecond timing. You can then sort by domain, usage, etc.