I’d like to avoid doing any needless HTTP requests on my site to improve performance. So, I’d like to include a local PHP on my server without using cURL. The problem is that the PHP I’m calling expects some parameters to be passed via HTTP GET. I’d like to keep it that way since I also want to be able to access those PHP files from other places.
What is the best way of doing this? Can I access the output of a local PHP file while giving it GET parameters?
includealso makes an HTTP request when you supply an HTTP URI to it, so instead of the client’s asynchronous include (for example using AJAX or an iframe) you do it synchronously on the server, therefore making the page load even slower.So while the include may work as intended (you want to include the output, right?), it will definitely not speed up your site.
Then alter those files and set the appropriate variables before including them. Or even better, refactor it into functions. For example, if the file you want to include looks like this:
Then refactor into a function and store in a separate file:
And call it appropriately:
(You might want to throw in an
isset()here and there.) Now you can alter your code that also needs this output:Now you don’t have to rely on URL or
$_GETorincludemagic, but simply use all functions as they’re meant to.