Session in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitin16286
Forum Newbie
Posts: 2
Joined: Fri Sep 10, 2010 4:16 am

Session in PHP

Post by nitin16286 »

i have two files in php both have the same code and the file is

Code: Select all

<?php
session_start();

$con = mysql_connect("","root",""); // here localhost and password will be filled accordingly
if (!$con)
{
	die('Connection failure: ' . mysql_error());
}

mysql_select_db("student",$con);

$fetch=mysql_query("SELECT * from student1") or die(mysql_error());
$row = mysql_fetch_array($fetch) or die(mysql_error());

sleep(10);

echo "Name: ".$row[0]."</br>";
echo " Age: ".$row[1]."</br>";
echo " Address: ".$row[2];

mysql_close($con);


?>
Now i have another file which has the same code as above except there is no sleep function used in it . Now when i run the file which is wothout sleep it displyas results in seconds however the file with sleep function takes it time.

Now the problem is if i load the file woth sleep function first then its delayed nature is reflected in another file which is without sleep() i.e now the file without sleep is taking longer time to open.

plz explain all this and possible solution to this problem

Localhost database connectivity and record retrieval all working fine
i mean when you open the file with sleep() in browser and then refresh the file without sleep() function then the file without sleep() function takes longer time to open
Last edited by nitin16286 on Fri Sep 10, 2010 5:00 am, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Session in PHP

Post by Benjamin »

:arrow: Moved to PHP - Code
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Session in PHP

Post by requinix »

Here's a few things for you to try to narrow it down. Do only one at a time. Individually.
1. Use "127.0.0.1" instead of "localhost" when connecting.
2. Run your SELECT with a LIMIT 1 attached.
3. Don't use sessions.
4. Close the connection immediately after getting a row.
Post Reply