Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phar doesn't work after 3.3.1 #3562

Closed
hermzz opened this issue Aug 17, 2023 · 19 comments
Closed

Phar doesn't work after 3.3.1 #3562

hermzz opened this issue Aug 17, 2023 · 19 comments

Comments

@hermzz
Copy link

hermzz commented Aug 17, 2023

Running the phpDocumentor phar worked fine for me up to 3.3.1 but it stopped working for 3.4.0. This cropped up initially in a gitlab pipeline, it had worked fine on Aug 15 but it stopped working Aug 16. Nothing in the pipeline environment changed between runs. I was also able to replicate the issue on my personal machine.

Expected behavior

Running the phpDocumentor phar file should work.

$ curl -L https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.3.1/phpDocumentor.phar > phpdoc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 22.0M  100 22.0M    0     0  19.2M      0  0:00:01  0:00:01 --:--:-- 23.8M
$ chmod +x phpdoc
$ ./phpdoc
phpDocumentor v3.3.1

Parsing files
 129/129 [============================] 100%
Applying transformations (can take a while)
 4/4 [============================] 100%
All done in 1 seconds!

Actual behavior

The phpDocumentor phar complains about Failed to open stream: phar error: no directory in "phar:///[redacted]/phpdoc/bin/phpdoc"

$ curl -L https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.0/phpDocumentor.phar > phpdoc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 14.4M  100 14.4M    0     0  9093k      0  0:00:01  0:00:01 --:--:-- 13.5M
$ chmod +x phpdoc
$ ./phpdoc
PHP Warning:  require(phar:///[redacted]/phpdoc/bin/phpdoc): Failed to open stream: phar error: no directory in "phar:///[redacted]/phpdoc/bin/phpdoc", must have at least phar:///[redacted]/phpdoc/bin/phpdoc/ for root directory (always use full p
ath to a new phar) in /[redacted]/phpdoc on line 10
PHP Fatal error:  Uncaught Error: Failed opening required 'phar:///[redacted]/phpdoc/bin/phpdoc' (include_path='.:') in [redacted]/phpdoc:10
Stack trace:
#0 {main}
  thrown in /[redacted]/phpdoc on line 10

Steps to reproduce the problem

  1. Download phar
  2. Set executable flag
  3. Run the phar file

Your environment

  • Version used: 3.4.0
  • Install method: phar
  • PHP version: 8.2.9 and 8.1.14
  • Operating system and version: Arch Linux and Ubuntu 20.04.5 LTS
@phpdoc-bot phpdoc-bot added this to Needs triage in phpDoc issue triage board Aug 17, 2023
@jaapio
Copy link
Member

jaapio commented Aug 17, 2023

I think the problem you are facing is caused by the fact the new release is a zipped phar file to reduce the size of the package. When I download the file using your curl command I get the same error however when I use the original file file it still works.

Making a symlink does work, that might help you to solve your issue with to much impact.

It's unclear to me right now why this happens, I will investigate this.

@hermzz
Copy link
Author

hermzz commented Aug 17, 2023

Interesting! Symlink or renaming to phpDoc.zip works.

MarcelBolten added a commit to elabftw/elabftw that referenced this issue Aug 19, 2023
seems like there is an issue with 3.4 for now
phpDocumentor/phpDocumentor#3562
@Moonomo
Copy link

Moonomo commented Aug 21, 2023

Making a symlink does work, that might help you to solve your issue with to much impact.

It isn't working on my end. 🤦🏼

My environment:

  • Version used: 3.4.0
  • Install method: phar
  • PHP version: 7.4.0
  • Operating system and version: MacOS Ventura 13.4.1
  • Device: Apple MackBook Air with M1 chip

Version 3.3.1 works just fine.

@jaapio
Copy link
Member

jaapio commented Aug 21, 2023

php 7.4 is not supported anymore.

@Moonomo
Copy link

Moonomo commented Aug 22, 2023

@jaapio right, it's failing because of the PHP 7.4. Thanks for the confirmation.

PhpDocumentor requires PHP 7.4 or higher to run

Looks like docs need to be updated accordingly.

@jakzal
Copy link

jakzal commented Aug 22, 2023

phive installation is broken in the same way.

@jaapio
Copy link
Member

jaapio commented Aug 22, 2023

Looks like docs need to be updated accordingly.

Thanks I will update them.

phive installation is broken in the same way.

That's sad... I still haven't found an solution for this.

@jaapio jaapio self-assigned this Aug 22, 2023
@jrfnl
Copy link
Contributor

jrfnl commented Aug 25, 2023

Another report here - this breaks automated workflows using setup-php to install the PHAR file (using PHP 8.1).

      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
          ini-values: display_errors=On
          coverage: none
          tools: phpdoc
        env:
          fail-fast: true

      - name: Generate the phpDoc documentation
        run: phpDocumentor
Run phpDocumentor -n
PHP Warning:  require(phar:///usr/local/bin/phpDocumentor/bin/phpdoc): Failed to open stream: phar error: no directory in "phar:///usr/local/bin/phpDocumentor/bin/phpdoc", must have at least phar:///usr/local/bin/phpDocumentor/bin/phpdoc/ for root directory (always use full path to a new phar) in /usr/local/bin/phpDocumentor on line 10

PHP Fatal error:  Uncaught Error: Failed opening required 'phar:///usr/local/bin/phpDocumentor/bin/phpdoc' (include_path='.:/usr/share/php') in /usr/local/bin/phpDocumentor:10
Stack trace:
Warning: require(phar:///usr/local/bin/phpDocumentor/bin/phpdoc): Failed to open stream: phar error: no directory in "phar:///usr/local/bin/phpDocumentor/bin/phpdoc", must have at least phar:///usr/local/bin/phpDocumentor/bin/phpdoc/ for root directory (always use full path to a new phar) in /usr/local/bin/phpDocumentor on line 10
#0 {main}

  thrown in /usr/local/bin/phpDocumentor on line 10
Fatal error: Uncaught Error: Failed opening required 'phar:///usr/local/bin/phpDocumentor/bin/phpdoc' (include_path='.:/usr/share/php') in /usr/local/bin/phpDocumentor:10
Stack trace:
#0 {main}
  thrown in /usr/local/bin/phpDocumentor on line 10

Source: https://github.com/PHPCSStandards/PHPCSUtils/actions/runs/5971668670/job/16201054407

@jaapio
Copy link
Member

jaapio commented Aug 25, 2023

I finally found something... not yet the solution though... it seems to be related to the new stub file included in our phar.

@jaapio jaapio closed this as completed in 42654d8 Aug 25, 2023
phpDoc issue triage board automation moved this from Needs triage to Closed Aug 25, 2023
@jaapio
Copy link
Member

jaapio commented Aug 25, 2023

ok, it turns out that php's phar does not support all filenames, so I had to introduce an alias name to make sure the bootstrap works as expected. This alias is some kind of internal reference to the current phar.

phar://phpdocumentor.phar is a valid file path... while phar:://phpdoc isn't.

jaapio added a commit that referenced this issue Aug 25, 2023
By using phar::mapPhar we allow the current phar to be renamed
while files can still be loaded by it's orginal name.

Fixes #3562
@jaapio
Copy link
Member

jaapio commented Aug 25, 2023

v3.4.1 willl be available within minutes. This should fix your issue.

Thanks for all the reports!

@jrfnl
Copy link
Contributor

jrfnl commented Aug 25, 2023

@jaapio Thank you! I'll restart the workflows and will report back.

@jrfnl
Copy link
Contributor

jrfnl commented Aug 25, 2023

Doc generation build is passing again!

P.S.: you may want to update this sentence in the intro for the 3.4.0 release changelog to make it clear support for 8.0 has also been dropped (that's now hidden away further down in the changelog)

General changes

In this release we upgraded to Symfony 6 and PHP 7 support has been droppped completely. We added support for php 8.2.
Interally we have restructured the pipelines to prepare for multi version support in the future.

NicolasCARPi added a commit to elabftw/elabftw that referenced this issue Aug 28, 2023
* add php codecoverage to cypress tests

* escape double less than

* fix phpdoc version
seems like there is an issue with 3.4 for now
phpDocumentor/phpDocumentor#3562

* add missing line end escape

* create directory first

* try to make test less flaky

* try double quotes

* fix sed command

* use a bash script

* fix phpcov path

* exclude src/commands during codecoverage with cypress

* merge coverage report also when running tests/run.sh

* don't test experiments page over and over again after login

* add more tests, cover edge case during schedule report creation

* add test for HeartBeat.php, enable coverage

* add cypress test for register.php

* add missing declaration

* fix some file path/names

* oops, some more

* update circleci config file

* more cypress tests on search page

* add input elemets

* more make and search test stuff

* add import test and fix csv import

* use typescript for cypress, add more test, fix some php stuff

* remove leftover js file

* error => e

* fix unit tests for getPage() of tags and teamgroups

* lint cypress test files and upload merged coverage report to codecov

* Update package.json

* avoid log injection
but this shoud not be a problem here at all

* singlequote quotes

* minor fixes

---------

Co-authored-by: Nicolas CARPi <nico-git@deltablot.email>
@jakzal
Copy link

jakzal commented Sep 7, 2023

I'm still getting an error with phive on Docker:

Notice: require(): zlib: data error in /tools/.phive/phars/phpdocumentor-3.4.1.phar on line 11

Warning: require(phar://phpdocumentor.phar/bin/phpdoc): Failed to open stream: phar error: internal corruption of phar "/tools/.phive/phars/phpdocumentor-3.4.1.phar" (actual filesize mismatch on file "bin/phpdoc") in /tools/.phive/phars/phpdocumentor-3.4.1.phar on line 11

Fatal error: Uncaught Error: Failed opening required 'phar://phpdocumentor.phar/bin/phpdoc' (include_path='.:/usr/local/lib/php') in /tools/.phive/phars/phpdocumentor-3.4.1.phar:11
Stack trace:
#0 {main}
  thrown in /tools/.phive/phars/phpdocumentor-3.4.1.phar on line 11
image

Interestingly, phpDocumentor works when image is being built, but not when I run it on the built image. Perhaps a docker issue.

@jaapio
Copy link
Member

jaapio commented Sep 7, 2023

Do you have the zip extension installed in php?

@jakzal
Copy link

jakzal commented Sep 7, 2023

Yes. I'm not expecting you to look into this btw.

Looking into the phar, most of PHP files are empty.

image

@jakzal
Copy link

jakzal commented Sep 16, 2023

I can reproduce the problem now.

  1. Start a PHP Docker container

    docker run -it --rm jakzal/phpqa:alpine sh
    
  2. Install phpDocumentor with phar

    phive --no-progress --home /tools/.phive install \
        --trust-gpg-keys 8AC0BAA79732DD42 phpDocumentor \
        -t /tools/.phive/tmp/f474e60df5620536af2224cbc21a1668 \
        && mv /tools/.phive/tmp/f474e60df5620536af2224cbc21a1668/* /tools/phpDocumentor
    
  3. Run phpDocumentor (works fine)

    /tools/phpDocumentor
    
  4. Run phpDocumentor again (phar is now corrupted)

    /tools/phpDocumentor
    

Other phar files on the image do not get corrupted.

image

@dharmann
Copy link

Hi@all, I'm facing a similar problem, but only the second time I run the phar.

My environment

  • Version used: 3.4.1
  • Install method: phar
  • PHP version: 8.1.2
  • Operating system and version: Ubuntu Linux 22.04.3 LTS
  • I've the zlib extension installed and working
  • I'm running the phar as normal user.

Steps to reproduce the problem:

FYI: I'm working into /tmp directory.

  1. Download phar
    $ wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.1/phpDocumentor.phar
  2. Set executable flag
    $ chmod +x phpDocumentor.phar
  3. Run the phar file
    $ ./phpDocumentor help (help command, for instance)

After these steps. from the second time I launch the phar onwards:
$ ./phpDocumentor help

I obtain the following result:

PHP Notice: require(): zlib: data error in /tmp/phpDocumentor.phar on line 11
PHP Warning: require(phar://phpdocumentor.phar/bin/phpdoc): Failed to open stream: phar error: internal corruption of phar "/tmp/phpDocumentor.phar" (actual filesize mismatch on file "bin/phpdoc") in /tmp/phpDocumentor.phar on line 11
PHP Fatal error: Uncaught Error: Failed opening required 'phar://phpdocumentor.phar/bin/phpdoc' (include_path='.:/usr/share/php') in /tmp/phpDocumentor.phar:11
Stack trace:
#0 {main}
thrown in /tmp/phpDocumentor.phar on line 11

Additionally I've extracted the phar before and after running it and seen that in the second extraction there are missing files. One for all phar://phpDocumentor.phar/bin/phpdoc

@jaapio
Copy link
Member

jaapio commented Sep 22, 2023

I created a new issue, please continue there, as this issue was different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

6 participants