简体   繁体   English

php PharData 致命错误

[英]php PharData Fatal Error

I'm downloading a tar.gz file from aws onto my localmachine for now.我现在正在从 aws 下载一个 tar.gz 文件到我的本地机器上。 I want to decompress it and unzip to read the contents.我想解压缩它并解压缩以阅读内容。 I'm getting an error when creating new PharData object with the file location:使用文件位置创建新的 PharData 对象时出现错误:

Fatal error: Uncaught exception 'UnexpectedValueException' with message
'unable to create temporary file for decompression of gzipped phar archive 
"/Applications/XAMPP/xamppfiles/htdocs/NB/admin/temp/ea975d07f1-response.tar.gz"' 
in /Applications/XAMPP/xamppfiles/htdocs/NB/admin/mcAdvanced.php:28 Stack trace: #0 
/Applications/XAMPP/xamppfiles/htdocs/NB/admin/mcAdvanced.php(28): 
PharData->__construct('./temp/ea975d07...') #1 {main} 
thrown in /Applications/XAMPP/xamppfiles/htdocs/NB/admin/mcAdvanced.php on line 28

And my php code is:我的 php 代码是:

file_put_contents("./temp/ea975d07f1-response.tar.gz", fopen($response_body_url, 'r'));
$phar = new PharData('./temp/ea975d07f1-response.tar.gz'); //Error here-line28

I think the permissions are correct.我认为权限是正确的。 I am able to unzip and view manually.我可以手动解压缩和查看。 Anybody have any advice?有人有什么建议吗?

Thanks!谢谢!

目录/文件的屏幕截图

Your webserver needs to have write access to the Operating System's $TEMP directory in order to extract the PHAR file.您的网络服务器需要对操作系统的$TEMP目录具有写入权限才能提取 PHAR 文件。

Use sys_get_temp_dir to see what directory this is so you can apply the correct permissions.使用sys_get_temp_dir查看这是什么目录,以便您可以应用正确的权限。

Alternatively, you can specify a different directory to which your webserver already has access to use as PHP's temp dir.或者,您可以指定一个不同的目录,您的网络服务器已经可以访问该目录作为 PHP 的临时目录。

This is a common issue when using compression with phar archives that are beyond a trivial size.当对超出普通大小的 phar 存档使用压缩时,这是一个常见问题。 The error originates from https://github.com/php/php-src/blob//ext/phar/phar.c#L2552 which seems to be triggered when php_stream_fopen_tmpfile() fails which is just an alias to _php_stream_fopen_temporary_file .该错误源自https://github.com/php/php-src/blob//ext/phar/phar.c#L2552似乎在php_stream_fopen_tmpfile()失败时触发,这只是_php_stream_fopen_temporary_file的别名。 Why this call is failing is not immediately clear.此次调用失败的原因尚不清楚。 Using sys_get_temp_dir shows that temp is at /tmp which does have the correct permissions (1777) and plenty of space.使用sys_get_temp_dir显示 temp 位于/tmp ,它确实具有正确的权限 (1777) 和足够的空间。

The workaround for this issue is to just not compress the archive.此问题的解决方法是不压缩存档。 I would argue that is not a very good answer, however, this is a long standing issue in phar and I wouldn't hold your breath for a near-term solution.我认为这不是一个很好的答案,但是,这是 phar 中长期存在的问题,我不会为近期的解决方案而屏住呼吸。

What user runs the Apache process?哪个用户运行 Apache 进程? Test it with exec('whoami') .exec('whoami')测试它。 I guess that it is only a permission problem for the $_SERVER["APP_POOL_ID"] .我想这只是$_SERVER["APP_POOL_ID"]的权限问题。 Grant read write to this identity.授予对此身份的读写权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM