Can't create identical PHAR files at different times

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,

I'm working on a command-line PHP project and want to be able to recreate the PHAR file that is my deployment artifact. The challenge is that I can't create two PHAR's that have identical sha1sums that were created more than 1 second apart. I would like to be able to exactly recreate my PHAR file if the input files are the same (i.e. came from the same git commit).

The following code snippet demonstrates the problem:
----------------------------------cut----------------------------------
#!/usr/bin/php
<?php
$hashes = array();
$file_names = array('file1.phar','file2.phar');

foreach ($file_names as $name) {
  if (file_exists($name)) {
    unlink($name);
  }
  $phar = new Phar($name);
  $phar->addFromString('cli.php', "cli\n");
  $hashes[]=sha1_file($name);
  sleep(1); // remove the sleep and the PHAR's are identical.
}
if ($hashes[0]==$hashes[1]) {
  echo "match\n";
 } else {
  echo "do not match\n";
 }
----------------------------------cut----------------------------------

As far as I can tell, the "modification time" field for each file in the PHAR manifest is always set to the current time, and there seems to be no way or overriding that. Even touch("phar://file1.phar/cli.php", $timestamp) gives the error:
    touch(): Can not call touch() for a non-standard stream

I've run the above code in PHP 5.5.9 on ubuntu trusty, but PHP 5.3 on RHEL5 also creates PHAR files that aren't identical.

Any help is appreciated.

Jason

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux