Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Versioning resolve.php without breaking the pages that call it

I have one PHP endpoint that every tool page on my site depends on. The homepage, the TikTok page, the Instagram page, the Facebook page, all of them send the pasted link to resolve.php and wait for a list of download fo

I have one PHP endpoint that every tool page on my site depends on. The homepage, the TikTok page, the Instagram page, the Facebook page, all of them send the pasted link to resolve.php and wait for a list of download formats back. That makes resolve.php the most dangerous file in the project. Change it carelessly and eight pages break at once, in front of real visitors, with no warning.

So I version it. Not with a framework and not with a proper API versioning scheme. With a few habits that fit a plain PHP site on shared hosting.

The first habit is simple: never rename a field in the JSON response. When I needed a new piece of information, the file size of each format, I added a size field next to the old ones. The old pages ignored it and carried on working. The new pages read it. If I had renamed url to download_url because it read better, every page calling the endpoint would have broken the moment the new file went live. Boring field names are a feature. I only add; I never rename or remove.

The second habit is a version field inside the response itself. Every reply from resolve.php carries api_version: 2 at the top. The JavaScript on the pages does not check it yet, but it is there for the day I need it. If a page ever starts behaving oddly after a deploy, the first thing I can do is look at which version the page actually received. It costs one line and it turns a mystery into a fact.

The third habit is about how I deploy a change that is too big for a safe addition. When I split one provider per platform, the response shape stayed the same, but the internals changed a lot. I did not overwrite the live file and hope. I uploaded the new version as a separate file first, pointed one low-traffic page at it, and tested it with real links on the live site. Only when that page behaved did I copy the new file over resolve.php. On shared hosting there is no staging server and no rollback button, so the second file is my staging server. The old file stays in place until the new one has proved itself, and keeping the last working copy one click away has saved me more than once.

The fourth habit is keeping the contract small. resolve.php takes a URL and returns formats, or it returns an honest error. It does not fetch the file, it does not log anything about the visitor, and it does not guess. Because the contract is small, I can change the inside of the endpoint, swap a provider, add a retry, change a timeout, without touching the pages at all. The pages only care about the shape of the answer, not how it was produced. That separation is the real versioning. The file name never changes, so the pages never need updating, and the behaviour inside can keep moving.

The last habit is the least technical one: I test after every upload, on the live site, with a real link I own. I paste a TikTok link into the homepage, a reel into the Instagram page, and I watch the formats come back. If a field changed shape and I missed it, that test catches it in a minute. Automated tests would be nicer, but a two-minute manual check on the real site beats a test suite I never wrote.

None of this is clever. It is the same discipline as keeping a shared JavaScript file in sync across eight pages: change one thing at a time, keep the old shape working, and prove it live before you call it done. The site I am describing is ramrom.io, a small downloader I built in plain PHP, and every page on it still calls the same resolve.php it called on the first day. That is the point. The endpoint has changed plenty since then. The pages never had to know.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.