file_get_contents performance

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
[)roi(];18118559 said:
Importance to debugging vital; importance to user inconsequential; its really about consumption time

You just flipped the script, please noob it down for me in simple terms.

Since you just said it's inconsequential to users which I completely disagree with, who on earth would wait 5 seconds for a web page to load?
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
You just flipped the script, please noob it down for me in simple terms
Just a perspective thing:
  • For a developer, working on the performance of a specific block of code is vital.
  • For the enduser; what really counts is how long do they have to wait before they can consume content. Or more specifically perceptive load time vs. actual load time.
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
[)roi(];18118601 said:
Just a perspective thing:
  • For a developer, working on the performance of a specific block of code is vital.
  • For the enduser; what really counts is how long do they have to wait before they can consume content. Or more specifically perceptive load time vs. actual load time.

That makes sense, hence why this exercise you guys helped with ie loading content from the DB instead of loading it from the API made my loading time of the landing page go from 5 seconds to 0.0029 seconds.
 

koeksGHT

Dealer
Joined
Aug 5, 2011
Messages
11,857
That makes sense, hence why this exercise you guys helped with ie loading content from the DB instead of loading it from the API made my loading time of the landing page go from 5 seconds to 0.0029 seconds.

Now more than 2 people can visit the page without it dying lol.
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
That makes sense, hence why this exercise you guys helped with ie loading content from the DB instead of loading it from the API made my loading time of the landing page go from 5 seconds to 0.0029 seconds.

Exactly; can be equated to a dining experience; the time between ordering food, to receiving food can be alleviated with fillers: music, drink, ...but also advanced preparation (e.g. ingredients partially prepared) -- helps to create the appearance that food preparation is expedient, even when process is not.
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
Now more than 2 people can visit the page without it dying lol.

[)roi(];18118685 said:
Exactly; can be equated to a dining experience; the time between ordering food, to receiving food can be alleviated with fillers: music, drink, ...but also advanced preparation (e.g. ingredients partially prepared) -- helps to create the appearance that food preparation is expedient, even when process is not.

Still rough work, just slapped on some styling so we can have a look, but it will change.

site.jpg
 

rward

Senior Member
Joined
Oct 26, 2007
Messages
865
Fcking succes!! Thank you @bio and @koeks

It works!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I learned, insert, update, select and cron jobs and pdo

Thor,

Don't forget to look at the official documentation to things when you first encounter them. Especially for services/servers that you are going to use often, like for MySQL - http://dev.mysql.com/doc/refman/5.7/en/ ( http://dev.mysql.com/doc/refman/5.7/en/sql-syntax-data-manipulation.html http://dev.mysql.com/doc/refman/5.7/en/data-types.html and http://dev.mysql.com/doc/refman/5.7/en/func-op-summary-ref.html )

Just how basic sql works (select * from * where * group by * order by * limit * ) and checking the list of available functions on the func-op-summary-ref.html page.
You're probably doing stuff in code that your database does 5 million times faster (and is built to do)..
 
Last edited:

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
Thor,

Don't forget to look at the official documentation to things when you first encounter them. Especially for services/servers that you are going to use often, like for MySQL - http://dev.mysql.com/doc/refman/5.7/en/ ( http://dev.mysql.com/doc/refman/5.7/en/sql-syntax-data-manipulation.html http://dev.mysql.com/doc/refman/5.7/en/data-types.html and http://dev.mysql.com/doc/refman/5.7/en/func-op-summary-ref.html )

Just how basic sql works (select * from * where * group by * order by * limit * ) and checking the list of available functions on the func-op-summary-ref.html page.
You're probably doing stuff in code that your database does 5 million times faster (and is built to do)..

I agree 100%, I am a bit vodka'd at the moment so text is blurry, but it makes sense! You guys are the best, this is a silly thing I am doing, but it opened my eyes up that I can use the DB since before I was a bit... afraid of entering the world of SQL, but now that I am in it, it does not seem all that daunting at all.
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
I am thinking now, is it a best practice to fire up the DB for everything even so small like this won't it be faster to somehow have php to write it out to a text file and take it from there or would the db approach we have be quicker?

Guess what I am trying to ask is how fast is a DB really and what affects it's speed and also how fast is a DB compared to like a "flat file" ?

Because to my noob mind I think reading files should be a lot quicker than connecting to MySQL DB each time.
 

gkm

Expert Member
Joined
May 10, 2005
Messages
1,519
Flat files are faster for small things, but DB's scale better and are simpler in the long run (more future proof kind of thing).

Also, writing to your local disk could be the start of a security vulnerability, so in general I consider it a bad practice, unless there is a very good reason.

So, in general I would recommend getting into the habit of using the database for everything you want to store.

Also, DB's are atomic (ACID), which means that you do not end up in situations where for a flat file you are reading it while you are writing it and then briefly show jumbled results. DB has transactions to prevent messes like that.
 
Last edited:

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
Flat files are faster for small things, but DB's scale better and are simpler in the long run (more future proof kind of thing).

Also, writing to your local disk could be the start of a security vulnerability, so in general I consider it a bad practice, unless there is a very good reason.

So, in general I would recommend getting into the habit of using the database for everything you want to store.

Also, DB's are atomic (ACID), which means that you do not end up in situations where for a flat file you are reading it while you are writing it and then briefly show jumbled results. DB has transactions to prevent messes like that.

Okey that makes sense yes, I will stick to the DB. This is an exciting world, I always wanted to build something where people can log in and out and now looking at the links @rward posted it doesn't seem all that daunting anymore.

If I keep my interaction with the database in that prepared statement way there is not too much that can go wrong in the form of injections and stuff or am I being noob here?

I want to be aware from a security point of view what to look out for even now when I am starting small. Might as well do it right from the start.
 

halfmoonforever

Expert Member
Joined
Feb 1, 2016
Messages
1,196
I would use cURL and it's ability to do asynchronous fetching of multiple URL's to get the load time down to the equivalent of just 1 call to the API. But I'm glad you're sorted and I can learn from this too :D
 

gkm

Expert Member
Joined
May 10, 2005
Messages
1,519
I would use cURL and it's ability to do asynchronous fetching of multiple URL's to get the load time down to the equivalent of just 1 call to the API. But I'm glad you're sorted and I can learn from this too :D

May depend on your exact setup, but this kind of thing can often consume all the threads on your web server, so it might be fast for the first couple of users, but result in horrible latencies or crashes if you have more concurrent users.

For something that changes independently of the user base, like the share prices, fetching the data out of band is usually the best option, since it works the same for one or one million users.

This makes interesting reading: http://www.reactivemanifesto.org/
Note, it is hard to achieve with tech like LAMP (which is why I like things like the Play framework), but at least be aware of it and do not shoot yourself in the foot with unbounded parallel work taking down your website.
 
Top