I have a script on a website, let's call it my_script.php. In that same server, I have a cakephp 2.3 application with a specific controller/action that runs certain background tasks. That function can be called via URL like http://example.com/controller/action/param1
Now I need to make it so every time my_script.php
is loaded, it calls the cakephp function I mention above sending a parameter.
I can do that easily using
$result = file_get_contents('http://example.com/controller/action/param1');
However, since both scripts are located in the same server, it seems to me that it's unnecessary having to make DNS requests, or even just use the IP of the server, to call that cakephp function.
Is there any way to make that call without using a public URL (and passing a parameter)? Just using file paths I mean. I've tried:
$result = file_get_contents('/controller/action/param1');
$result = file_get_contents('/path/to/app/webroot/index.php/controller/action/param1');
$result = file_get_contents('/path/to/app/webroot/index.php?controller=controller&action=action¶m1=param1');
But none of those seemed to work. Is it possible or should I just use the full URL? Or maybe not using file_get_contents()
but something else?