I am zipping entire server content(for backup purposes) via php / PharData:
$phar = new PharData(SYS_ROOT.'/project.zip');
$phar->buildFromDirectory(SYS_ROOT.'/');
SYS_ROOT is constant defining path to web root (. dot in this case). Everything works fine except for missing empty folders in the resulting zip. The folders are necessary.
I tought about Phar::addEmptyDir, but that would require another iteration through the folders to determine which are empty. Tried recursivedirectoryiterator to no avail(also skipped empty folders) as well :(
I've never used this but looking at the documentation it says the following:
Phar::buildFromDirectory — Construct a phar archive from the files within a directory.
Which means that it is behaving as expected. However I think you could use buildFromIterator and then also compress since this is for backups I think I'd go with that one.