Did something pretty much similar recently, but using Python as weapon of choice. I can do the job as good in PHP, no problem. You'll have an excerpt of Python code in your inbox, just for your convenience, for review. If you like what you see, please reach out to discuss further. Looking forward, best regards.