473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

!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 1662
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 logincredentials, 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 logincredentials, DOESN'T CLOSE ITS CONNECTION, and
recycles the connection when ANY script uses the same logincredentials.
So PHP is doing things right performancewise.
I don't think you'll gain a lot of performanceimprovement 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 logincredentials, 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 logincredentials, DOESN'T CLOSE ITS CONNECTION, and
recycles the connection when ANY script uses the same logincredentials.
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*******@attglobal.net
==================
Feb 5 '07 #5
"Eric Layman" <erricson@layspíše v diskusním příspěvku
news:11*************@sp6iad.superfeed.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
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...
1
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
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...
2
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...
2
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
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...
0
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...
7
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...
1
by: shenoivis | last post by:
need of other data types in enum
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.