當我嘗試使用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
天蓬老师2017-05-16 16:47:33
跑下這個,
$ ./configure --help | grep curlwrappers
應該可以看到這個選項是「試驗性質」的,在http://us.php.net/manual/en/wrappers.... 裡也找不到curl作為wrapper的正式說明。
況且,確實會導致fopen工作不正常。