Apache causing CPU to spike when POSTing


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Apache causing CPU to spike when POSTing
# 1  
Old 05-15-2009
Apache causing CPU to spike when POSTing

Hello all. I've built a SAMP server on Solaris 10 using Apache 2.2.9 and PHP 5.2.6

For the most part everything seems to be working except when I post form data, Apache causes the CPU to max out. Sometimes the script will complete about 40 seconds later. Other times I have to stop Apache to get the CPU under control.

Memory use is not effected only the CPU.

I wrote 4 simple PHP scripts to try and isolate the problem. The scripts are called: burt1.php, burt2.php, burt3.php and burt4.php

(Named after some Burt's Bees I have on my desk!)

The point of the scripts is to gather two numbers (burt1), write them to MySQL (burt2), read previously entered numbers and ask you to pick one (burt3), pass this picked number to burt4.php.

Burt4 will read the database where the picked number is, retrieve it and the number marked as "second" in that row, add them together and display the result.

Simple stuff.

Burt1 and Burt2 run fine.

When I select a number in burt3 and click submit, Apache goes nuts and maxes out the CPU.

I never get to the burt4 script and have to kill Apache to get the CPU under control.

Any thoughts or suggestions on why the CPU is maxing out would be very much appreciated.

Below I have posted the 4 scripts. They were quickly written in Notepad. So apologies for the poor formatting.

Thank you for your comments.
~Robert

<?php
//burt1.php
//connect to MySQL and select the database
require_once('./burt_connect.php');
if ($dbc) {
echo "good connection to the burt database";
}else{
echo "failed to connect";
}

echo '<br>';
echo '<br>';
echo "a quick mysql form post and read test";
echo '<br>';
?>
<form action = "burt2.php" method = "POST">
<p>First number:<input type = "text" name = "first_number"/></p>
<p>Second number:<input type = "text" name = "second_number"/></p>
<p><input type = "submit"/></p>
</form>
<?php
//end of burt1 script
?>
-----------------------------------------------------------------
<?php
//burt2.php
//connect to MySQL and select the database
require_once('./burt_connect.php');
$first_number = $_POST['first_number'];
$second_number = $_POST['second_number'];
if ($dbc){
echo "burt2 has a good database connection";
}else{
echo "failed to connect to the database";
}
echo '<br>';
echo '<br>';
echo "the first number is: $first_number";
echo '<br>';
echo "the second number is: $second_number";
echo '<br>';
echo '<br>';
$user_id = time();
$query1 = "insert into numbers (user_id, first_number, second_number) values ('$user_id', '$first_number', '$second_number')";
$result1 = mysql_query($query1);
if ($result1) {
echo "wrote to the database";
}else{
echo "write to the database, failed";
}
echo '<br>';
?>
<form action = "burt3.php">
<input type = "submit" value = "go to burt3">
</form>
<?php
//end of burt2 script
?>
------------------------------------------------------------------
<?php
session_start();
//burt3.php
//connect to MySQL and select the database
require_once('./burt_connect.php');
echo "burt 3 script";
echo '<br>';
echo "pick from the first numbers below to add the second";
$query1 = "select first_number from numbers order by first_number ASC";
$result1 = mysql_query($query1);
while ($row=mysql_fetch_array($result1)) {
$pick = $row[first_number];
echo '<br>';
echo "a number you can use is: $pick";
}
echo '<br>';
$_SESSION['whatever'] = "solaris";
if (mysql_close($dbc)) {
echo "connection closed";
echo '<br>';
} else {
echo "connection not closed";
echo '<br>';
}
?>
<form action = "burt4.php" method = "POST">
<p>select a first number: <input type = "text" name = "number"></p>
<p><input type = "submit"></p>
</form>
<?php
//end of burt3 script
?>
-------------------------------------------------------------------
(***never get to this script***)
<?php
session_start();
//burt4.php
$value = $_SESSION['whatever'];
echo "burt 4 script";
echo '<br>';
echo "the session variable value is: $value it should be solaris";
echo '<br>';
$get_number = $_POST['number'];

//connect to MySQL and select the database
require_once('./burt_connect.php');
if ($dbc) {
echo "good connection to the database";
}else {
echo "no good connection to the database";
}
echo '<br>';
$query1 = "select * from numbers where first_number = '$get_number'";
$result1 = mysql_query($query1);
while ($result1) {
$first_number = $row[first_number];
$second_number = $row[second_number];
}
$total = $first_number + $second_number;
echo "the numbers we are going to add are: $first_number and $second_number";
echo '<br>';
echo "they equal: $total";
echo '<br>';
echo "end of burt4 script";
?>
# 2  
Old 05-16-2009
First, please encapsulate your scripts in [code] tags so we can read them.

Second, is Apache configured to use PHP as a module or as CGI?

Third, this line here might give some trouble:
Code:
$pick = $row[first_number];

first_number is neither a symbol nor string. What is it?
# 3  
Old 05-17-2009
Otheus:

Thanks for responding. Sorry about not using the code tags. That was my first time posting code and did not know about them.

Apache is configured as a CGI. Here is the Apache configure command I used:

'./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-mysql' '--with-curl=/usr/local/lib' '--with-curlwrappers' '--enable-fastcgi' '--enable-force-cgi-redirects'

first_number is a number. I tried it with both single and double quotes - got the same result each time, a maxed out CPU.

Thanks for pointing the missing quotes.
# 4  
Old 05-17-2009
The Apache2 httpd.conf includes the following lines:

LoadModule php5_module modules/libphp5.so

AddType application/x-httpd-php .php .phtml
# 5  
Old 05-17-2009
ok, good. those lines with $row[first_number] don't make any sense to me.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Load spike

Hi, I would try to find out the load spike of memory utilization in the Servers before 2-3 hours ago., As the alerts are being triggering out by the altering system. I try to find out the utilization via the sar command, but how come I know which user and command is consuming more of memory... (6 Replies)
Discussion started by: gsiva
6 Replies

2. UNIX for Dummies Questions & Answers

Is it possible to combine multiple CPU to act as a single CPU on the same server?

We have a single threaded application which is restricted by CPU usage even though there are multiple CPUs on the server, hence leading to significant performance issues. Is it possible to merge / combine multiple CPUs at OS level so it appear as a single CPU for the application? (6 Replies)
Discussion started by: Dissa
6 Replies

3. Red Hat

CPU high - apache real server OK, virtual server not

Got two RHEL servers - one real and one virtual/cloud. Both run apache web server. When traffic is applied, CPU seems to go quite high on virtual one (20%) but real is not really affected. Worry is that a further increase in traffic will see a problem. Experience of RHEL is limited. Whats... (2 Replies)
Discussion started by: psychocandy
2 Replies

4. Red Hat

apache high cpu load on high traffic

i have a Intel Quad Core Xeon X3440 (4 x 2.53GHz, 8MB Cache, Hyper Threaded) with 16gig and 1tb harddrive with a 1gb port and my apache is causing my cpu to go up to 100% on all four cores heres my http.config <IfModule prefork.c> StartServers 10 MinSpareServers 10 MaxSpareServers 15... (4 Replies)
Discussion started by: awww
4 Replies

5. Solaris

Solaris 10 - script creating huge spike in Kernel CPU

I'm running on Solaris 10, and I have a script that's running on several machines. Basically, what it's doing is: * tail -f | grep one or more log files into a temp file * Every minute or so, copy that temp file to a second temp and zero the first * Sed through the 2nd temp to pull out a user... (2 Replies)
Discussion started by: Rorgg
2 Replies

6. Solaris

Multi CPU Solaris system shows 100% CPU usage.

Hello Friends, On one of my Solaris 10 box, CPU usage shows 100% using "sar", "vmstat". However, it has 4 CPUs and prstat and glance are not showing enough processes to justify high CPU utilization. ========================================================================= $ prstat -a ... (4 Replies)
Discussion started by: mahive
4 Replies

7. Solaris

How to check CPU spike between certain priod of time

Hi, Does anyone know how to check which process has been used the most CPU between certain time period? say I have noticed CPU spike happend between 1:00 to 1:30 now it is 3:00 o'clock already. Is there anyway to find out what process/PID use the most CPU then? Thanks a lot (3 Replies)
Discussion started by: uuontario
3 Replies

8. UNIX for Dummies Questions & Answers

how to get persistant cpu utilization values per process per cpu in linux (! top,ps)

hi, i want to know cpu utilizatiion per process per cpu..for single processor also if multicore in linux ..to use these values in shell script to kill processes exceeding cpu utilization.ps (pcpu) command does not give exact values..top does not give persistant values..psstat,vmstat..does njot... (3 Replies)
Discussion started by: pankajd
3 Replies

9. Solaris

Find any spike in CPU usage a hour ago

Folks, I need to find out from the system logs ( or elsewhere ) if the CPU utilization reached say 90% an hour ago from now. Is there a way out. (2 Replies)
Discussion started by: kavera
2 Replies
Login or Register to Ask a Question