简体   繁体   中英

Issue with using wildcards in php glob()

I have a strange situation happening with PHP glob() and wondered if anyone has encountered it. 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:

$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.

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. 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).

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.

Update 2 It's doing it again. 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. I found when I cut that number down to 712, glob returns the array. Adding one more image, total of 713, makes it hang. The difference in size between the two are 1.62GB and 1.63GB respectively. I tried changing PHP settings but they had no effect. I added a small txt file to the directory and it still hung up. 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. 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. So, something must have happened to mess things up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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