Maybe it is intended but i find it weird that "PharData compress" nests the original tar inside of the compressed tar.gz. So you have to open the .tar.gz and you will see the original.tar which you have to open again?
Code:
$tarPath = $_SERVER['DOCUMENT_ROOT'].'api/sample2.tar';
$pharData = new PharData( $tarPath );
$pharData->addFile( $_SERVER['DOCUMENT_ROOT'].'api/callback_post.txt', 'callback_post.txt' );
$pharData->compress(Phar::GZ);
Php 7.4
These are two diferent concepts. Tar packs files, while gz compress tar package.
You may try ZipArchive