While it's written in Python rather than PHP, you can do that with the utility jc.
gzcat Packages.gz | jc --pkg-index-deb