!Need advice from other PHP developers.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Layman

    !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 **
    ----------------------------------------------------------
    Best Usenet Service Providers 2025 ranked by Newsgroup Access Newsservers, Usenet Search, Features & Free Trial. Add VPN for privacy.

  • Erwin Moller

    #2
    Re: !Need advice from other PHP developers.

    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

    Comment

    • Toby A Inkster

      #3
      Re: !Need advice from other PHP developers.

      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!

      Comment

      • J.O. Aho

        #4
        Re: !Need advice from other PHP developers.

        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

        Comment

        • Jerry Stuckle

          #5
          Re: !Need advice from other PHP developers.

          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.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Petr Vileta

            #6
            Re: !Need advice from other PHP developers.

            "Eric Layman" <erricson@laysp íše v diskusním pøíspìvku
            news:1170652022 _7441@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.)


            Comment

            Working...