SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is it best practice to code the SQL to return (CONCAT) string links

    I had lots of PHP code that checked:
    PHP Code:
    if ($row[1] == 'Y') {
      echo 
    'whatever'
    } else {
      echo 
    'something else'

    Now I write that into the SQL statement since I have heard its faster and scales better. Without metrics on my server, I can not verify.

    Something like:

    IF(active='Y', CONCAT('<a href=\"../foldera/page2.php?id=', ag_ID, '&tID=3&lID=N\">Link1</a>'), CONCAT('<a href=\"../folderal/page2.php?id=', ag_ID, '&tID=3&lID=Y\">Link2</a>'))

    Your thoughts?

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i put together a test case for you. using the attached files, i ran an apache benchmark using 1000 requests with 30 concurrent connections. see the attached text files to see the code i tested with.

    here is the table:
    Code:
    CREATE TABLE `testtable` (
     `active` char(1) NOT NULL default '',
     `ag_ID` int(11) NOT NULL default '0',
     KEY `active` (`active`),
     KEY `ag_ID` (`ag_ID`)
    ) TYPE=MyISAM
    the test results show php is slightly faster.

    php results:
    Code:
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   1.3      0      10
    Processing:    20  279 144.1    280     680
    Waiting:       20  279 144.1    280     680
    Total:         20  279 144.1    280     680
    sql results:
    Code:
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   2.3      0      10
    Processing:    30  292 150.7    290     721
    Waiting:       30  291 150.8    290     721
    Total:         30  292 150.7    290     721
    so, in your sepcific case, doing it in PHP is faster.
    Attached Files Attached Files

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WOW! Thanks so much! What did you use to do this?

    If I had Zend studio to comile it, I wonder if it would be even better to use php. Or if I had MySQL 5 with stored procs, if that would be better.

    Since I have either, I'll stick with this.

    Once again, many many thanks for this.

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    apache comes with a benchmarcking tool called ab. you pass it a url and it connects over and over again, timing the results.

    it's VERY useful for finding queires that don't use indexes well or use a lot of temporary table space or memory. in that case, the page will load quickly with only one connection to the webserver, but multiple concurrent connections perform very poorly.

  5. #5
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that is wicked cool. I'll have to read up on it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •