Currently I'm loading a few external sites via iframe to showcase content. However since those sites are geographically far away from my users and my server, it's really really slow for them.
I recently came across the php method file_get_contents() and read that it would be faster since its server side scripts. My question is, from a user's perspective. Will file_get_contents load external sites faster for my users than iframe or is there some other php methods faster than iframe I can use.
Thanks
If you fetch all these sites on the server before sending anything to the client, the client will see nothing until your server has loaded every single page. If you use iframes, the client is loading the sites asynchronously and will see something earlier. If your server would periodically fetch these pages and cache them, you'd have an advantage.
But, loading the sites on the server and embedding their HTML would also mean you'd have to do a lot of processing server-side to rewrite and fix all external includes these sites have (stylesheets, Javascript, images), since they're now being served from a different domain.
In short: probably not.
Think about it, you would act as a proxy:
+---------------+ +-------------+
| external site |<---far far away------| your server |
+---------------+ +-------------+
^
|
+----------------+
| client browser |
+----------------+
This adds another layer but does not bring the external site nearer to anyone. Conclusion: If anything, it will be slower.
Problems with using only file_get_contents()
Best solution is :
Load and save the external file as a cron job.
Save the file along with the page requisites(css and js) on your server.
Load this local file in an iframe resulting in asynchronous display and fast user experience.