Simple-as-pi PHP blog without a database - The WWW

Users browsing this thread: 1 Guest(s)
hades
Long time nixers
If you've ever wondered how easy it'd be to make your own blog without a database, let me assure you that it's pretty simple.

But it's stupid. If your blog suddenly gets popular, constantly opening and closing and reading from text files will stress out your server a lot more than reading from a single database would. That, and for the most part, if you're using a free host, they keep your databases on something with decent I/O like an SSD, while keeping your server root on a larger, but slower drive (Mainly because Databases need to be fast, and don't take up as much space as the average user's document_root folder, which may be stuffed with bootleg movies or some shit)

Bottom line, don't use this unless you really wanna just play with it and see how it ticks - it is quite interesting.

Here it is on github: https://github.com/hadenodom/php-file-blog

Basically, posts are stored in the posts/ folder, as numbered files with no extension. Just text files. Each numbered file is a post; the higher the number, the more recent the post. The files can have any html in them, nothing is off limits. The first line of each file should be the title, though. I'll explain that in just a second.

Index.php counts the number of files in posts/, and it uses that variable to determine the three most recently uploaded files (based on their names). It displays links to the posts, and reads the three most recent files, and displays the first line out of each file as the text for the link to that post (that's why the first line of the file should be the title). The link goes to "blog.php?post=1" (if you're going to post 1) ; This basically refers you to blog.php with the variable post set at 1.

Blog.php checks for the post variable when it loads. If it's referred to without a post var set, it loads and shows all of the posts (You might wanna make it show only ten or something if you post a lot...) If it's referred with one (such as post=1 in the previous example), it'll load and show that post.

Have fun with this, you guys. And hopefully, you can learn a little bit of PHP file operations by reading through it.
trgc
Members
Looks pretty interesting. Time to freshen up my PHP!
Klan9 > Plan9! (H0pe)
Klan9foLyfe
srp
Long time nixers
Well done, dbcp! I'll be using this on my website once I resign the html a litle (maybe add bootstrap).
~Seraphim R.P.
the artistnixer formerly known as vypr formerly known as sticky
z3bra
Grey Hair Nixers
Great post, and argument against file based blogs. But don't you think that serving blog posts from a database can be slower than simply accessing plain HTML files (think about good old HTML pages, not fetched through PHP).

I personally write my blog in plain HTML, which is totally static. Moreover, I host it myself, so I don't have any SSD to "speed up" file access, so would you think That (in my case) it'd be better for me to switch to a DB based posting ?
BANGARANG, MOTHERFUCKER
hades
Long time nixers
(04-12-2013, 05:17 AM)z3bra Wrote: Great post, and argument against file based blogs. But don't you think that serving blog posts from a database can be slower than simply accessing plain HTML files (think about good old HTML pages, not fetched through PHP).

I personally write my blog in plain HTML, which is totally static. Moreover, I host it myself, so I don't have any SSD to "speed up" file access, so would you think That (in my case) it'd be better for me to switch to a DB based posting ?


Well, remember, both pages have a function that counts all files in the posts folder, so if you have a ton of files, that can slow it down I guess. That, and blog.php lists every single post, but you could change it to list only the first 20.
zygotb
Long time nixers
Thanks for sharing... I'm having a look now...
Someone doesn't appreciate my php generated image!
trgc
Members
I'm going to make an improved/cleaner version of this...
Klan9 > Plan9! (H0pe)
Klan9foLyfe
hades
Long time nixers
I'm probably gonna make a lot of improvements to it as well. I intend to remove the styling, and clean up the variable and function naming(like replace $i with $pagecount)