当我尝试使用curl和管道操作符直接传给php的去执行下载回来的install的时候报错了:
$ curl -s https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...
The download is corrupt, retrying...
Downloading...
The download is corrupt, retrying...
Downloading...
The download is corrupt (internal corruption of phar "/work/doc/composer.phar" (truncated entry)), aborting.
然后我手动下载了install:
$ curl -s https://getcomposer.org/installer > composer
然后手动跟踪错误出在了哪里,然后跟踪到了一个try...catch语句:
......
try {
// test the phar validity
echo $file;
$phar = new Phar($file);
// free the variable to unlock the file
unset($phar);
break;
} catch (Exception $e) {
if (!$e instanceof UnexpectedValueException && !$e instanceof PharException) {
throw $e;
}
unlink($file);
if ($retries) {
if (!$quiet) {
out('The download is corrupt, retrying...', 'error');
}
} else {
out('The download is corrupt ('.$e->getMessage().'), aborting.', 'error');
exit(1);
}
}
......
当 new Phar的时候出现了错误,于是我把这段代码拿出来,单独执行之后,php报了这样的错误:
$ cat test.php
<?php
$file = '/work/doc/composer.phar';
$phar = new Phar($file);
unset($phar);
然后执行这个test.php,看到这样的错误:
$ php test.php
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'internal corruption of phar "/work/doc/composer.phar" (__HALT_COMPILER(); not found)' in /work/doc/test.php:5
Stack trace:
#0 /work/doc/test.php(5): Phar->__construct('/work/doc/compo...')
#1 {main}
thrown in /work/doc/test.php on line 5
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'internal corruption of phar "/work/doc/composer.phar" (__HALT_COMPILER(); not found)' in /work/doc/test.php:5
Stack trace:
#0 /work/doc/test.php(5): Phar->__construct('/work/doc/compo...')
#1 {main}
thrown in /work/doc/test.php on line 5
但是我已经有一份下载回来的脚本命名为 composer.phar,我把test.php命名为composer.phar也不行,下边是我的php的编译参数:
./configure --prefix=/opt/php/default --with-config-file-path=/opt/php/default/etc --with-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-libdir=lib64 --with-xmlrpc --enable-zip --enable-soap --with-pear --enable-pdo --with-pdo-mysql --with-gettext --enable-exif --enable-wddx --enable-calendar --enable-ftp --enable-dba --enable-sysvmsg --enable-sysvshm --enable-debug --enable-maintainer-zts --with-pcre-regex --enable-gd-jis-conv --with-apxs2=/opt/apache/default/bin/apxs