I have a cron job that calculates the disk space on ServerA
I have a MySQL database on ServerB that stores the disk space values
ServerA in not allowed to access MySQL database on ServerB (Rules out direct MySQL Connect)
ServerA cannot open files on ServerB (Rules out include();)
ServerA and ServerB have no shell_exec() abilities
I've tried header("Location: http://ServerB.com/record.php?disk_space=$disk_space"); using a get method then the receiving file $_REQUEST the values but it only works when run through browser and not when run as a cron job.
I think there are no proper alternatives. But I'm happy with a peculiar or scruffy solution. Please put forward your ideas. TIA
-
curl, file_get_contents() or even wget from a cron job would all work fineuser557846– user5578462013年05月14日 22:04:41 +00:00Commented May 14, 2013 at 22:04
-
This boils down to a question of what network protocol you'd like to use. If the MySQL server also runs a web server, you can treat that side like a normal dynamic webpage and just hit the URL from the cron job (via PHP itself or wget, curl, etc). Depending on your setup you may want more security in this layer, in which case SSH or something similar might be a better choice. Do you have any restrictions/preferences in this regard?Matt Kantor– Matt Kantor2013年05月14日 22:07:51 +00:00Commented May 14, 2013 at 22:07
2 Answers 2
You can hit external scripts directly through a number of HTTP libraries -- as well as file_get_contents().
See:
- file_get_contents - accepts a URL as the filename
- curl - HTTP library
- HTTP - another HTTP library
You could even use sockets to make the request:
Lots of options (more than included here). Easiest, if your needs are simple, is just file_get_contents.
Comments
create a file with an extension of php and write your script with mysqli_connect, etc and handle what you want to do as if you go the this page on your browser yourself than run cron job of that file , that should do it.
1 Comment
mysqli_connect will not work from external servers.