473,883 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

!Need advice from other PHP developers.

Hi,

Many years ago when I first learnt abt web dev in school,

I was taught this methodology:

[Open connection]

<html>
blah blabh

[execute sql]
[loop thru recordset]

<table>[data] </table>

[recordset close]
[end loop]

<html>

[Close connection]
Over the peroid of time, I noticed that the above method may cause
connection problems on heavy sites.

Recently, I have use another method to retrieve data from server

[Open Connection]
[declare 2D array]
[loop thru recordset]
[2D array] = [data]
[recordset.close]
[end loop]
[Close connection]

<html>

[loop thru the 2D array]
<table>[2d array's DATA] </table>
[end array loop]

</html>

It performs better as all the data retrieveal and processing are all
processed at the beginning of the page.

Need comments and advise please.

1. Are there better ways to manage connections and easier data retrieval to
ensure performance of the site under heavy load?

2. Are there any potential pitfalls regarding my 2nd method of data
retrieval?

Thanks


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Feb 5 '07 #1
5 1688
Eric Layman wrote:
Hi,

Many years ago when I first learnt abt web dev in school,

I was taught this methodology:

[Open connection]

<html>
blah blabh

[execute sql]
[loop thru recordset]

<table>[data] </table>

[recordset close]
[end loop]

<html>

[Close connection]
Over the peroid of time, I noticed that the above method may cause
connection problems on heavy sites.

Recently, I have use another method to retrieve data from server

[Open Connection]
[declare 2D array]
[loop thru recordset]
[2D array] = [data]
[recordset.close]
[end loop]
[Close connection]

<html>

[loop thru the 2D array]
<table>[2d array's DATA] </table>
[end array loop]

</html>

It performs better as all the data retrieveal and processing are all
processed at the beginning of the page.
Hi,

That is how I retrieve data too, via ADODB (PHP) GetArray().
Nothing wrong with it. It even offers you handy last minute scrubbing over
an array instead of awkward recordsets.
>
Need comments and advise please.

1. Are there better ways to manage connections and easier data retrieval
to ensure performance of the site under heavy load?
PHP recycles its connection behind your back.
If scriptA.php connects to a database, a connection is build based on the
login-credentials (host, database, username, password, etc).

If scriptB.php, scriptC.php, etc, use the same logincredential s, which is
almost always the case in webdriven databases, you'll find that they do NOT
need the connection/authentication overhead that scriptA.pp needed.
PHP remembers the logincredential s, DOESN'T CLOSE ITS CONNECTION, and
recycles the connection when ANY script uses the same logincredential s.
So PHP is doing things right performancewise .
I don't think you'll gain a lot of performanceimpr ovement by using another
approach.

>
2. Are there any potential pitfalls regarding my 2nd method of data
retrieval?
Just be aware how your elements in your array represent 'strange values'
coming from the database, like NULL. Are they stored as empty string? Or
are they really (PHP)NULL? Make sure you check and know.
>
Thanks


Regards,
Erwin Moller
Feb 5 '07 #2
Eric Layman wrote:
[Open Connection]
[declare 2D array]
[loop thru recordset]
[2D array] = [data]
[recordset.close]
[end loop]
[Close connection]
After this, all your data is now stored in $2dArray, using up memory. If
you loop through the recordset, reading one line at a time and outputting,
you use less memory. For small bits of data, that's unlikely to be a
problem though.

By the way, you may want to put more consideration into your message
subject lines in future. "!Need advice from other PHP developers." could
easily apply to 90% of the messages to this group. A more specific subject
line which may help clue readers in to what your post will be about would
have been "Caching SQL results into an array" or somesuch.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 5 '07 #3
Erwin Moller wrote:
>1. Are there better ways to manage connections and easier data retrieval
to ensure performance of the site under heavy load?

PHP recycles its connection behind your back.
If scriptA.php connects to a database, a connection is build based on the
login-credentials (host, database, username, password, etc).

If scriptB.php, scriptC.php, etc, use the same logincredential s, which is
almost always the case in webdriven databases, you'll find that they do NOT
need the connection/authentication overhead that scriptA.pp needed.
That depends on which connect function you use, *_connect or *_pconnect.

PHP remembers the logincredential s, DOESN'T CLOSE ITS CONNECTION, and
recycles the connection when ANY script uses the same logincredential s.
If you use *_connect, the connection is closed when the script has been
executed, even if you don't use *_close, while *_pconnect leaves the
connection alive.

>2. Are there any potential pitfalls regarding my 2nd method of data
retrieval?

Just be aware how your elements in your array represent 'strange values'
coming from the database, like NULL. Are they stored as empty string? Or
are they really (PHP)NULL? Make sure you check and know.
And don't get too much data, it's easier this way to hit the PHP max RAM size,
specially if you throw the data into functions in bad ways and you may have 2+
copies of the original array.

--

//Aho
Feb 5 '07 #4
Eric Layman wrote:
Hi,

Many years ago when I first learnt abt web dev in school,

I was taught this methodology:

[Open connection]

<html>
blah blabh

[execute sql]
[loop thru recordset]

<table>[data] </table>

[recordset close]
[end loop]

<html>

[Close connection]
Over the peroid of time, I noticed that the above method may cause
connection problems on heavy sites.

Recently, I have use another method to retrieve data from server

[Open Connection]
[declare 2D array]
[loop thru recordset]
[2D array] = [data]
[recordset.close]
[end loop]
[Close connection]

<html>

[loop thru the 2D array]
<table>[2d array's DATA] </table>
[end array loop]

</html>

It performs better as all the data retrieveal and processing are all
processed at the beginning of the page.

Need comments and advise please.

1. Are there better ways to manage connections and easier data retrieval to
ensure performance of the site under heavy load?

2. Are there any potential pitfalls regarding my 2nd method of data
retrieval?

Thanks


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Eric,

This will help free up MySQL resources with heavily used sites, but will
require more memory in PHP to hold your data.

For a single thread, things will run more slowly due to the extra
processing required to buffer the data in an array.

For the entire system, things may run more quickly or more slowly - it
all depends on where your constraints are. Personally, I can't see that
it will really help that much other than releasing the connection a
slight bit more quickly. And if you're that connection-constrained, the
number of MySQL connections is probably too low.

Personally, I don't do any extra buffering. But I don't request
resources before I need them, and I release resources as soon as I'm
through with them. That means, for instance, I don't do a SELECT until
I'm ready to use the data, and I close the result set as soon as I'm
through with the data. I also close the connection as soon as I'm done
with all MySQL requests.

But you claim this is faster - I'd like to see some real benchmarks on
this. I really suspect the increase in speed is more a matter of
perception (quite easy to do).

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 5 '07 #5
"Eric Layman" <erricson@laysp íše v diskusním příspěvku
news:11******** *****@sp6iad.su perfeed.net...
Hi,

Many years ago when I first learnt abt web dev in school,

I was taught this methodology:

[Open connection]
<html>
blah blabh
[execute sql]
[loop thru recordset]
<table>[data] </table>
[recordset close]
[end loop]
<html>
[Close connection]

Over the peroid of time, I noticed that the above method may cause
connection problems on heavy sites.

Recently, I have use another method to retrieve data from server

[Open Connection]
[declare 2D array]
[loop thru recordset]
[2D array] = [data]
[recordset.close]
[end loop]
[Close connection]
<html>
[loop thru the 2D array]
<table>[2d array's DATA] </table>
[end array loop]
</html>
If you can read say tens or hundreds of records then the first method is
better. Not oveload server memory and is quickly.
But if you can read thousand or more records then is better to use other
methods.
[open connection]
[open temporary file]
[loop thru recordset]
[write to file]
[end loop]
[close connection]
[close file]
[open file]
[loop thru lines]
[print to html]
[end loop]
[close file]

By my experience all servers have less RAM then disk space ;-) and read or
write text file is a simple task for server.

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Feb 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1517
by: Tamir Khason | last post by:
Hi, all This time I need advice - no help ;) I have following architecture: 30 server with 100 devices connected each one Each "device" implement some (between 1 and 10) different interfaces All devices implements one basic interface I have N clients to work with all devices. Options of implementation 1) Remoting - Owful "overhead" (IMHO) 2) Just regilar custom TCP (sending well-known string commands to hub server
1
1565
by: Chris Lane | last post by:
Need Advice on prebuilt Exception Assemblies Please take a look at my post on the Titled: Need Advice on prebuilt Exception Assemblies posted on 04/21/04 Thank
3
2664
by: hazly | last post by:
I'm very new in the web technology and need advice on search engine. I want to develop a portal using PHP and MySQL on Linux. Need to know on the following features : 1. search engine that could search my portal (mySQL, PDF, Ms Word & others) 2. search engine that could search to few web sites specified by user/programmer
2
1277
by: Andrew Meador - ASCPA, MCSE, MCP+I, Network+, A+ | last post by:
I have Visual Studio 2003 Enterprise Architect Edition. I have been away from the programming area for a while - since before Studio 2005 came out. I am financially tight and am wondering if going to Studio 2005 is warranted considering what I already have available? Is there anywhere I am going to have trouble if I port my projects over to 2005 in a while when I am better ready financially, or should I bite the bullet and do it now to...
2
1328
by: shapper | last post by:
Hello, Where can I find some information on .NET naming conventions? For example, controls prefixes, properties, etc? And is it normal to name variables with prefixes? Dim sName As String
40
1697
by: RvGrah | last post by:
I've been writing in C# for about 4 years now, coming from VB.net and VB6 before that, in which I know I'm not alone. I found learning C#, at least to the extent that I use it in developing database front- ends, to be rather painless. The language and VS ide seemed comfortable pretty quickly. Some of the enhancements that have come along in the last two updates (via VS 2005 and 2008) like Generics and now Linq and anonymous types etc,...
0
937
by: dihola | last post by:
Hi all, I am developing 2 websites (A and B) that share a lot of pages and classes, and I wonder if I am doing it the right way. I have extracted the common classes and created master pages for all common pages in a third project (C), as follows (roughly simplified): --C ---page1.master ---page2.master ---commonclass1.cs ---commonclass2.cs
7
2176
by: SM | last post by:
Hello, I have a index.php template (2 columns). The right columns contains a bunch of links (interviews, poems, etc...) The left columns contains the actual article. So if I click on a link on the right menu, the article shows on the left column. The links have an url that look like this: http://www.myweb/library/?doc=194uf7s39
1
1276
by: shenoivis | last post by:
need of other data types in enum
0
9953
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10868
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9588
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7980
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.