PHP Performance Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

PHP Performance Question

Post by Aristona »

Hi,

I am planning on coding an education website. (For reference it looks like w3schools)
Currently I am using a html file as my navigation. (menu) Since the website will be education related and I want users to post articles too, it will be a huge load for the database so I need some performance tips.

Right now the website is running on a VPS. It is not released yet so I couldn't test my website performance & reliability. We are planning about moving on a dedicated server, if the VPS cannot hold the website anymore.

Question 1
Everything in the website will be directly taken from database. (Mssql) Articles, links, navigation, anything. As for example, whenever a visitor connects to website, there will be a sql query gathering links for the navigation menu from the database. When he browses an article, there will be another query getting links for the navigation sub menu. There will also be a query to get article from the database.

What's the most professional way to code a website like this? What do you suggest?

Question 2
Articles are going to be saved in database. Probably they will be huge (PHP side alone will take like 1000 papers) so what's the best way to save them in the database? What kind of coloumn should we be using? (e.g varchar(max)) The maximum lenght I know is 8000 characters, probably it is not even enough for a single page.

Any suggestions on this?

Question 3
To get most performance as possible, should I be doing something like "Make a timer script, which automatically converts everything in database into html files every 24 hours, so when a visitor browses the PHP section, page automatically includes page_php_lesson1.html(which contains the information of database)" There will be less queries to the database, but will it improve my website performance greatly or there will be a minimal increase at all? Also, what's the performance difference between including a .html file with 50kb of text and doing a SQL Query and getting 50kb text with select command ?

Also a suggestion on this would be great.

Thank you.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP Performance Question

Post by Jonah Bron »

Answer 2
That of course depends on the size you expect. Here's some data types:
http://w3schools.com/sql/sql_datatypes.asp

Answer 3
Yes, you should cache to HTML. But if I were you, I'd save to HTML on edit/creation, instead of a cron/daemon.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Performance Question

Post by califdon »

I would not store thousands of lengthy text articles in a database. I would probably store them as HTML partial pages and store the path names in the database. If you provide the qualified user with an input form that allows for the equivalent of BB codes, you could probably parse them rather easily and generate the exact code you want to store, complete with paragraphs, bolding, size, whatever you decide you want to allow in your articles. But I would store them as independent files, ready to include() into your page format for display when called on.

I have used a free javascript toolbar that permits insertion of HTML tags quite successfully. Take a look at http://alexking.org/projects/js-quicktags.
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

Re: PHP Performance Question

Post by Aristona »

I didn't thought about it. Probably that's what I'll do.
I am coding my own BBCode system. I'll just update the script to save the text into few seperate files and save their path into database. I am thinking about seperating files by [SEPERATE] BBCode tag. Once that command is used, the rest of the page will be stored in a different file so the user can designate where his article will end.
I want to ask, may it lead to any exploits or database related security will be enough? (Apart from folder security and file security.)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Performance Question

Post by Benjamin »

califdon wrote:I would not store thousands of lengthy text articles in a database. I would probably store them as HTML partial pages and store the path names in the database.
This is actually a good idea. I once built a clone of Wikipedia (with all of their data), and was able to run it on a VPS. Page loads were very fast because I only used a lookup table to determine what files to load. The only problem I ran into was running out of Inodes. Each file/folder on Unix systems require an Inode and it's not possible to create any more files when you run out. I was able to get my hosting provider at the time to increase the number of Inodes I was allowed to use so it worked out.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP Performance Question

Post by Jonah Bron »

Aristona wrote:...I am coding my own BBCode system...
See this project: http://code.google.com/p/cryobb/ . It might save you a lot of trouble :)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Performance Question

Post by califdon »

Aristona wrote:I want to ask, may it lead to any exploits or database related security will be enough? (Apart from folder security and file security.)
I am not a security expert (others here are), but I would think that storing the users' input in HTML files instead of in the database would actually reduce the opportunity to use exploits based on SQL injection. Any time you accept data input by a user, you need to consider what a malicious user might enter. There is a lot of information on this online.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: PHP Performance Question

Post by s.dot »

Since it's not released yet, I would not worry about optimizing for performance.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

Re: PHP Performance Question

Post by Aristona »

Thanks for the replies. :)
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHP Performance Question

Post by Darhazer »

Question 1:
Make sure all your queries use proper indexes. Use memcached to lower database load

Question 2:
BLOB

By the way, you can use Lucene / Solr to provide a search in the articles text if you need to. This is possible even if you decide to store the actual file content in file

Question 3:
Memcached
Post Reply