Best practice for writing page pages using PHP?

I want to record the number of page hits, and I think it's just file-based or SQLite storage.

The file option
File contains only an integer incremented each time a page is visited, and each page has a unique file name. If I open a file using the mode a , I can write, but if you can not close, so every time to save and close the file?

SQLite variant
Simple table with PageName and Hits columns. The same question again allows you not to close it, to save from opening and closing db every time?

+5
source share
4 answers

If you really need to do this yourself, you should go with the sqlite method. Despite the small overhead (due to opening the database file), there can also be significant advantages when storing structured data.

You can, for example, add a date field, and then receive daily / hourly / monthly / any data for each page.

You can also add an IP address for each visitor, and then retrieve the visit data. This way, you can easily extract user behavior data for your site.

You can also save the user agent and your visitor so that you know which browsers you should target or not.

, . , . , , , .

+4

Google Analytics. .

PHP , . ip- ( ), . . , , date, numOfUnique.

- . 24 .

+8

. PHP , -, . , db, . , db- ?

0

, ( , , Google Analytics).

:

. , , , , - .

SQLite:

I think this is probably the way to go if you haven't opened the database yet. I doubt that opening / closing db will be a bottleneck every time - try it and the profile.

0
source

All Articles