简体   繁体   English

在php glob()中使用通配符的问题

[英]Issue with using wildcards in php glob()

I have a strange situation happening with PHP glob() and wondered if anyone has encountered it. 我有一个奇怪的情况发生在PHP glob(),并想知道是否有人遇到过它。 This problem may be too broad for here, but trying anyway. 这个问题可能过于宽泛,但无论如何都要尝试。

I'm running the following: 我正在运行以下内容:

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty

PHP 5.6.20-1+deb.sury.org~trusty+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

My glob function was working before using: 在使用之前我的glob函数正在工作:

$images = glob($path . '/' . $id .'.*');

Then it suddenly stopped working. 然后它突然停止工作。 I've not really changed anything on the server or in any other code. 我没有真正更改服务器或任何其他代码中的任何内容。 These are different things I've tried just to see what would happen 这些是我尝试过的不同的事情,看看会发生什么

$images = glob($path . '/' . $id . '.{jpg,jpeg,png,gif}', GLOB_BRACE); //works
$images = glob($path . '/*.jpg'); // doesn't work 
$images = glob($path . '/*'); // doesn't work

Basically, anytime I use the wildcard, no matter the position, the script (ran from a command line) just sits there. 基本上,无论何时我使用通配符,无论位置如何,脚本(从命令行运行)都只是坐在那里。 No error, no return, nothing. 没有错误,没有回报,没有。 I even tried using GlobIterator with the same results. 我甚至尝试使用GlobIterator获得相同的结果。

I've tried uninstalling and reinstalling PHP, created a new directory with some temp files to perform tests, and nothing I do seems get it working again. 我已经尝试卸载并重新安装PHP,创建了一个带有一些临时文件的新目录来执行测试,而我所做的一切似乎都让它再次运行。 There are about 1000 files in the directory, so it should take all that long to match (I've let it sit for an hour). 目录中有大约1000个文件,所以它应该花费所有那么长的时间来匹配(我让它坐了一个小时)。

So, wondering if anyone has run into this problem before or perhaps know of a solution? 那么,想知道是否有人遇到过此问题或者可能知道解决方案? This is mainly out of curiosity because I've already rewritten the code not using glob() in some places that required a wildcard. 这主要是出于好奇,因为我已经在一些需要通配符的地方重写了不使用glob()的代码。

Update 2 It's doing it again. 更新2它再次这样做。 Hanging when using the wildcard. 使用通配符时挂起。 I ran the below tests: 我运行了以下测试:

// not working
    var_dump(glob('/vagrant/biospex-2.0/storage/scratch/1-8c6b410c42da62d37e7aabc00a61e258/*'));
    // not working
    var_dump(glob('/vagrant/biospex-2.0/storage/scratch/1-8c6b410c42da62d37e7aabc00a61e258/*.jpg'));
    // not working
    var_dump(glob('/vagrant/biospex-2.0/storage/scratch/1-8c6b410c42da62d37e7aabc00a61e258/*.{jpg,jpeg,gif,png,tif,tiff}', GLOB_BRACE));
    // not working
    var_dump(glob('/vagrant/biospex-2.0/storage/scratch/1-8c6b410c42da62d37e7aabc00a61e258/5715116ac46988ff1a8b4b8f.*'));
    // working
    var_dump(glob('/vagrant/biospex-2.0/storage/scratch/1-8c6b410c42da62d37e7aabc00a61e258/5715116ac46988ff1a8b4b8f.jpg'));

Update 3 In my directory there are 1100 images. 更新3在我的目录中有1100个图像。 I found when I cut that number down to 712, glob returns the array. 我发现当我将该数字减少到712时,glob返回数组。 Adding one more image, total of 713, makes it hang. 再添加一个图像,总共713个,使其挂起。 The difference in size between the two are 1.62GB and 1.63GB respectively. 两者之间的大小差异分别为1.62GB和1.63GB。 I tried changing PHP settings but they had no effect. 我尝试更改PHP设置,但它们没有任何效果。 I added a small txt file to the directory and it still hung up. 我在目录中添加了一个小的txt文件,它仍然挂起。 So not really sure what is happening here. 所以不确定这里发生了什么。 I should also mention this is using Ubuntu on Virtualbox hosted on a Windows machine with shared folders. 我还要提一下,这是在使用共享文件夹的Windows机器上托管的Virtualbox上使用Ubuntu。 For now, I'm simply going to use an iterator. 现在,我只想使用迭代器。

Not really a solution but I ended up rebuilding my local dev server from scratch. 不是真正的解决方案,但我最终从头开始重建我的本地开发服务器。 The glob() function started working after that. 之后glob()函数开始工作。 So, something must have happened to mess things up. 所以,必须要发生一些事情。

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

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