Jump to content

Generic question .. why does it take longer to load a page in php than in asp


Recommended Posts

I have a generic question that may or may not have a simple answer.  If code samples are required, I can provide them.

 

I originally had a small site for a project at work that was coded in asp.  When I loaded data or performed searches, data was loaded instantly and I can quickly switch between pages with no delay.  I have since started rewriting the pages in php with nearly exactly the same functionality, just in the different code.  Now when I load a page in .php the data displays almost instantly like before, but the status bar still shows "Page is loading...." for several seconds.  If I try to changes pages again while this message is there, the behavior is not as it should be.  If I wait for the page to finish loading, then the page changes are processed correctly.

 

I do not know what I did differently between asp and php but since All I am doing is doing one SQL query and displaying the results on the page the load time is not intensive (VERY small data sets right now).  Is there a general reason why this may happen with php, or would you need code samples to compare to try to find what I did wrong.

 

Thanks

the query itself doesn't, as the data is displayed immidiately on the page.  it is doing something after displaying the data that I do not know what it is, because I have no code to process after displaying the table.

 

I will post code snippets shortly

This is a simple example, just a stupidly simple page to pull out URL bookmarks that have been saved in the database

 

This is a page in .asp

 

<%
Dim rs
Dim strSQL

Dim adoCon
Set adoCon = Server.CreateObject("ADODB.Connection")
AdoCon.Open

'Create an ADO recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

'Initialize the strSQL variable with a SQL statement to query the database
strSQL = "Select * FROM weblinks ORDER BY Abstract"

'open the record set with the sql query
rs.Open strSQL, adoCon

'loop through the recordset
Response.Write("<center><table border=0>")

Do While not rs.EOF
Response.Write("<tr><td>")
Response.Write("<a href=" & rs("URL") & " target=""_new"">" & rs("Abstract") & "</a>")
Response.Write("</td><td>")
Response.Write(rs("Comment"))
Response.Write("</td></tr>")
rs.MoveNext
Loop
Response.Write("</table></center>")

rs.Close
Set rs = Nothing
Set adoCon = nothing
%>

 

compared to the same functionality in php

<?php
if($connection = mssql_connect($myServer,$myUser,$myPass)){
mssql_select_db($myDB,$connection);
if($sql = mssql_query("Select * FROM weblinks ORDER BY Abstract"))	{
	echo "<center><table>";
	while($row = mssql_fetch_array($sql)) 		{
		echo "<TR><TD>";
		echo "<a href=" .$row[2] . " target=_new>" . $row[3] . "</a>";
		echo "</TD><TD>";
		echo $row[4];
		echo "</TD></TR>";
	}	
	echo "</TABLE></center>";
}
else	{
	echo "Error: " . mysql_error();
}
}
else{
echo "Error: " . mysql_error();
}
?>

 

and as I said before, the data is loaded nearly instantly and displayed in my table, but the status of the page is still shown as loading and says "Transferring data from <server>" for a few seconds even after the data is displayed and I am pretty confused as to why this is happening.  Do I have to close a connection, uninitialize variables or something ?

hmm well you could manually close the connection with

 

mysql_close($connection);

 

but php automatically does that when the script is done.  Same with the vars.  I mean, php is a server-side script same as asp; stuff won't be sent off to the client until the script is done executing, so I don't really think that will make a difference. ...

It most probably to do with how your server is configured rather than PHP. As CV said if PHP was still processing the script you'll just get a blank page. PHP does not outpot data a bit a time. The following script proves this:

echo 'Hello';

sleep('2'); // sleep for 2 secounds

echo ' world';

If you ran that PHP will outut 'Hello world' after two seconds has passed. It wont output Hello and then world 2 seconds after.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.