[PHP-DB] Is my Hosting service full of it?

2003-02-08 Thread pthes
I had trouble the other day. Ran a survey which generated about 700
responses an hour. It ran fine, then about 90 minutes in everything slowed
up. The hosting service suspended our domain claiming our survey was
overload the server. We had run the survey previously using PERL as the
scripting language. It worked OK then. The only significant change in the
scripting is that we switched to PHP from PERL.

Here are some claims from the hosting service:

Comment 1
Your survey, http://www.erespond.ino/thestar, is the cause of the server
crashing.

It is exceptionally PHP and MySQL heavy and unfortunately not the kind of
application you can safely run in a shared-hosting environment.

It is severely depleting resources on the server and denying other hosting
clients access to their sites.

This sort of survey should only be run on its own dedicated server, though
I'm not sure that would help in this case as the PHP scripting seems to be
running at above the necessary resources.

Comment 2 re: perl vs php
Yes, PHP would make a difference. Though it may be faster, it can devour
resources and grind everything to a halt.

If you had success running this survey previously in Perl, then I would
suggest doing the same now.

Comment 3: claim scripts as redundant
After checking out your PHP scripts for this survey, it's our view that they
are employing some redundant processing which is the cause of the memory
drain on the server.

Basically, it appears to be processing the same information over and over
again when it adds something new.

Comment 4:
We currently running PHP Release 4.1.2-3 on this server. We are waiting for
the stable release of PHP 4.3 for our servers.

In response to your questions:

So you suggest leaving the db open? What happens when someone bails out
before the end? Would that then cause another problem?

- You should be able to initiate a db close after a certain amount of time.



We had about 600-700 hits an hour for the survey. Is that too much volume
for you?

- Nope. We can do about 300 per second. The problem was the PHP and MySQL
applications eating memory.



Is the actual problem the scripting or the graphics that are loaded during
the survey?

- The scripting. We can serve about 20 million hits per day for regular
files.



I've been researching some sites regarding resources for php, mysql and
perl. General feeling seems to be that PHP is more efficient and doesn't
create any signifcant resource needs over perl.

- Very true. However, if the coding isn't done well it can devour a server.
I've seen it happen countless times over the past few years. Same goes for
CGI of course. But if your other script ran without incident, it seems
obvious that the CGI version is the better choice for now.


Are concurrent connects with mysql the problem?

- They certainly don't help. The MySQL server is shared amongst other sites
on this same server and obviously can only handle so much happening at once.

Comment 5: response to I don't believe php is worse than perl
CGI scripts are called once a form has been completed, the script then runs
quickly and closes itself. A pHp page May open a connection to mySQL at the
opening of the page, or later in it: either way instead of having the
information passed to mysql in a separate place, it is done in the same
place.

It gives the impression of being more efficient(since a step is skipped) but
for high traffic operations it can bog down a mySQL server, Especially if it
is a shared one.


I wondering if anyone has an opinion of whether I'm dealing with people who
don't know what they're doing. Do any of their comments make sense.
I'd be glad to provide further clarification if desired. I just have a real
feeling that I'm not getting knowledgable answers.
Thanks in advance.




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Is my Hosting service full of it?

2003-02-08 Thread pthes
Here's an example of code:

I have multiple page form. When the submit of each page is clicked it calls
a php script that then opens the dbase, checks if the user has already
replied to the page (for those who use the back arrow  of the browser),
writes the data, and then calls the next page.

Here's one script:

?php
session_start();
$datein=date(YmdHis);
session_register(datein);
include(filewithpasswordanddatabaselocation.inc);


$IP=$REMOTE_ADDR;

 $query = INSERT INTO habits
(datein,readcurrent,weekday,saturday,sunday,globe,tosun,post,metro,other,oth
erdesc,ipaddress,dow,speed,whenread)
values
('$datein','$readcurrent','$weekday','$saturday','$sunday','$globe','$sun','
$post','$metro','$other','$otherpaper','$IP','$dow','$internet','$whenread')
;
$result = mysql_query($query);

if  ($readcurrent == yes) {
 header(Location: ../pages/sections.php);
}
else {
 header(Location: ../pages/category1.php);
}
?

The connection file looks like this:
?php
$host=localhost;
$user=username;
$password=passwordgoeshere;
$database=databasegoeshere;

$connection = mysql_connect($host,$user,$password)
   or die (couldn't connect to server);
$db = mysql_select_db($database,$connection)
   or die (Couldn't select database);
?

One question that has arisen from all this is whether I should be using
pconnect() rather than connect()?
Thanks for the info so far.



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Is my Hosting service full of it?

2003-02-09 Thread pthes
Thanks for the comments,. I'm putting some code here to hopefully get an
idea of what is considered inefficient when dealing with mysql. I'm confused
because all I'm doing is collecting the data from a form and writing it to
the db. I have about 30 pages in the survey, so a script similar to this is
called after each page.

?php
session_start();

include(loginfile.inc);
$connection = mysql_connect($host,$user,$password)
   or die (couldn't connect to server);
$db = mysql_select_db($database,$connection)
   or die (Couldn't select database);

$intable = tablename;

/* this is the duplicate check section */
$sql = SELECT * FROM $intable WHERE datein = '$datein' AND itemID='$itemID'
;

$mysql_result = mysql_query($sql,$connection);
$num_rows = mysql_num_rows($mysql_result);

if ($num_rows == 0) {
/* insert if no dupes */
$query = INSERT INTO itemsread (itemread,itemID,datein) VALUES
('$itemread','$itemID','$datein');
$result = mysql_query($query);
}
else
{
/* update if existing timestamp */
$query = UPDATE $intable SET itemread='$itemread' WHERE datein='$datein'
AND itemID='$itemID' ;
$result = mysql_query($query);
} # end else
mysql_close($connection);

It seems pretty simple to me. What am I missing?



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php