I have only a couple thousand records in a MySQL db that can be called dynamically via php/url params (page.php?id=123). I also have a gnarly legacy function that pulls all the info for that page from the db, and generates a flat .html file based on a title field for each record. Every time a record is updated, this function is run and the page is regenerated.
It works well enough, but with a major rewrite around the corner and tons of intermingling html/php and hideous conditional logic in said function, I’d like to be able to update the php page (which works perfectly without the function), and then as records are updated in the backend, a simple command is called that hits page.php?id=updated_id and spits out an HTML page in the /pages directory, for example.
I was thinking about trying wget but before I go trying system stuff in PHP I thought I’d see if anyone has done anything similar?
The goal is, instead of updating this crazy function that writes html every time there is a design change, I can just edit the php file and change the post-update function to point to page-v1.php.
Do you really need to go the route of generating the HTML and then returning it. It’s a good solution for creating a v.fast site as there’s little work done for each user request.
A more normal way of achieving something similar is to add some level of caching either to your application or by putting a reverse proxy (maybe varnish, lighttpd, squid) in front of the web server.
edit: If it’s just a case of wanting to request a URL from within another page you can do this with
file_get_contents()or any other PHP “file” commands if you have url wrappers enabled. If you want a nicer, more configurable HTTP client from within PHP take a look at cURL