Archive for March 2011

PHP and Large File Sizes

Published on March 28, 2011

It’s incredible to me that in 2011, programming languages still have problems with files larger than 2GB in size. We’ve had files that size for years, and yet overflow problems in this arena still persist. At work, I ran into this problem trying to get the file size of very large files (between 3 and 4 GB in size). The typical filesize() call, as shown below, would return an overflowed result on a very large file:

$size = filesize($someLargeFile);

Because PHP uses signed 32-bit integers to represent some file function return types, and because a 64-bit version of PHP is not officially available, you have to resort to farming the job out to the OS. In Windows, the most elegant way I’ve found so far is to use a COM object:

$fsobj = new COM("Scripting.FileSystemObject");
$f = $fsobj->GetFile($file);
$size = $file->Size;

Uglier hacks involve capturing the output of the dir command from the command line. There are two bug reports filed on this very issue: 27792 and 34750. The newest of these was filed in late 2005; a little more than 5 years ago! It’s sad to see a language as prolific as PHP struggling with a problem so basic. Perhaps this issue will finally get fixed in PHP 6.

Brief Thoughts on Firefox 4

Published on March 27, 2011

As I tweeted recently, Firefox 4 is to the 3.x line what Windows 7 is to Windows XP. It really feels like a worthy successor in so many ways. Tabs on top is a great enhancement, and I especially like the tabs-in-the-title-bar approach. I’m really able to maximize my screen real estate with these options. Surprisingly, I don’t miss the status bar or menu bar as much as I thought I would (and yes, I know the menu bar is still present; I’ve simply chosen to turn it off). The orange “Firefox button” is a little strange, and takes some getting used to, but I can live with it.

The biggest improvement in my eyes is the ability to pin certain sites as “app tabs.” Currently, I have GMail and Twitter pinned open. I am the world’s worst at closing Firefox down completely at various points during the day. I don’t know why I do this, but knowing I have some app-tabs open will hopefully help me break this terrible habit. One other great improvement worth mentioning is start-up time, which is notably faster. They’ve really caught up to (though not surpassed) Chrome in this regard, which has always been lightning fast to boot up. Hopefully this trend will continue.

Calls to system() in Windows

Published on March 22, 2011

I recently ran into a stupid problem using the system() call in C++ on Windows platforms. For some strange reason, calls to system() get passed through the cmd /c command. This has some strange side effects if your paths contain spaces, and you try to use double quotes to allow those paths. From the cmd documentation:

If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (“) characters:

  1. If all of the following conditions are met, then quote characters on the command line are preserved:
    • no /S switch
    • exactly two quote characters
    • no special characters between the two quote characters, where special is one of: &<>()@^|
    • there are one or more whitespace characters between the two quote characters
    • the string between the two quote characters is the name of an executable file
  2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character.

As you can see from this documentation, if you have any special characters or spaces in your call to system(), you must wrap the entire command in an extra set of double quotes. Here’s a working example:

string myCommand = "\"\"C:\\Some Path\\Here.exe\" -various -parameters\"";
int retVal = system(myCommand.c_str());
if (retVal != 0)
    // Handle the error

Note that I’ve got a pair of quotes around the entire command, as well as a pair around the path with spaces. This requirement isn’t apparent at first glance, but it’s something to keep in mind if you ever find yourself in this situation.

Copyright © 2004-2019 Jonah Bishop. Hosted by DreamHost.