Jump to content

Archived

This topic is now archived and is closed to further replies.

jbreits

Efficiency

Recommended Posts

I'm designing a site that uses php and a MySQL database, but I want to make it as efficient as possible so as to not put too much load on my hosting company's server. I have a couple questions about speeding things up.

1. For MySQL connectivity, is it more efficient to use the standard mysql functions within php or to use the ADOdb classes? How about ADOdb lite? Persistent connections are probably not a good idea right (I seem to have found that they will probably hit the max number of open connections to the database)?


2. If I use ADOdb, should I take advantage of caching?


3. It appears that my hosting company has the Zend optimizer installed (via the phpinfo() function). Do I need to do anything to take advantage of this, or will it automatically optimize my files?


4. Is it more efficient to use static HTML in conjunction with php? i.e. which of these 2 is more efficient (when the concept is applied to a larger scale):

php only
[code]
<?php
  if (IsUserLoggedIn ())
  {
    echo ('You are logged in as: '.$_SESSION['UserName']);
    echo ('<br>');
    echo ('<a href="logout.php">Logout</a>');
  }

  echo ('<table width="100%">');
  
  echo ('<tr>');
  echo ('<td width="50%">');
  echo ('User Name: ');
  echo ('</td>');
  echo ('<td>');
  echo ('<input type="text" name="UserName" id="UserName" size="7" maxlength="50">');
  echo ('</td>');
  echo ('</tr>');
  
  echo ('<tr>');
  echo ('<td>');
  echo ('Password: ');
  echo ('</td>');
  echo ('<td>');
  echo ('<input type="password" name="Password" id="Password" size="14" maxlength="50">');
  echo ('</td>');
  echo ('</tr>');
  
  echo ('</table>');


?>    
[/code]

or static html with php
[code]
<?php
  if (IsUserLoggedIn ())
  {
    echo ('You are logged in as: '.$_SESSION['UserName']);
    echo ('<br>');
    echo ('<a href="logout.php">Logout</a>');
  }
?>  

  <table width="100%">
  
  <tr>
  <td width="50%">
  User Name:
  </td>
  <td>
  <input type="text" name="UserName" id="UserName" size="7" maxlength="50">
  </td>
  </tr>
  
  <tr>
  <td>
  Password:
  </td>
  <td>
  <input type="password" name="Password" id="Password" size="14" maxlength="50">
  </td>
  </tr>
  
  </table>

[/code]


Thanks!
jbreits

Share this post


Link to post
Share on other sites
hey to make it easier with echoing you can go like this:

[code]
<?php
echo <<<html
Show the text in here!
html;
?>
[/code]

or you can do it through a variable:

[code]
<?php
$content = <<<html
This is the top bit
html;
if(session_is_registered("member")){
$content .= <<<html //You put the . to add extra to the variable
Welcome member!
html;
}

echo $content;
?>
[/code]

Either is effective, but i use the variable.

Share this post


Link to post
Share on other sites
I really thought I would have more people weigh in on this topic. I'm just trying to create my scripts so that use minimal server resources.

1. What are people's thoughts on ADOdb? Is it more efficient than the mysql functions in PHP?

2. Is embedding PHP in html a more efficient way to go? For example, if I have a form that might be re-populating itself based on the $_POST variables, is it more efficient to jump in to PHP mode once and output the entire form with values, or to primarily use HTML mode, but jump in to PHP mode for each value in the form:

<input type="text" name="username" size=30 value="<?PHP echo ($_POST[username]); ?>">

Thanks,
jbreits

Share this post


Link to post
Share on other sites
1) I don't suggest using ADO. Use the included PHP libraries. From what I've found, they're faster. I'd challenge anyone else to suggest otherwise.

2) I don't know about taking advantage of the Zend optomizer. I suggest you contact your host about that.

3) The second option is far more efficient. Keep in mind that everything you pass through a PHP function has to be parsed by the PHP processor. If you send just HTML with PHP mixed in, it will ignore the HTML and hence parse your document faster. And just as a side note, the parenthesis are unnecessary for echos.

4) <input type="text" name="username" size=30 value="<?PHP echo ($_POST[username]); ?>"> is faster, but it can be done even easier:
<input type="text" name="username" size=30 value="<?=$_POST['username']?>">

Share this post


Link to post
Share on other sites
Thanks for the response. I will skip the ADO stuff and keep as much stuff out of PHP as possible. I'll see what I can find out about Zend.

Thanks!
Jbreits

Share this post


Link to post
Share on other sites

×

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.