Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // assumes we're on a 32-bit system
- $fp = fopen($large_file, 'rb'); // assuming $large_file is 4GB or more
- fseek($fp, PHP_INT_MAX, SEEK_SET);
- echo ftell($fp), "\n"; // works as expected (displays value of PHP_INT_MAX)
- fseek($fp, 1, SEEK_CUR); // call simply fails
- echo ftell($fp), "\n"; // (displays value of PHP_INT_MAX)
- fread($fp, 1); // works okay
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1)
- // (one would expect the previous fseek($fp, 1) call to do the same as the fread call, but anyway...)
- fseek($fp, -1, SEEK_CUR); // works okay
- echo ftell($fp), "\n"; // (displays value of PHP_INT_MAX)
- fread($fp, 1);
- fseek($fp, 1, SEEK_CUR); // works okay
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
- fseek($fp, -1, SEEK_CUR); // doesn't work! I'm guessing there's code to check if the file position would become negative, and deny the call if so
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
- // odd 8192 byte limitation to fseek'ing forward
- fseek($fp, 8192, SEEK_CUR); // doesn't work!
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
- fseek($fp, 1, SEEK_CUR); // also fails!
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
- // restart everything
- fseek($fp, PHP_INT_MAX, SEEK_SET);
- fread($fp, 1);
- fseek($fp, 8191, SEEK_CUR); // this works okay
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1+8191)
- fseek($fp, 1, SEEK_CUR); // doesn't work!
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1+8191)
- // it seems that there's some 8K buffer or similar with fseek - we need to "reset" this buffer with an fread to go further
- fread($fp, 1);
- fseek($fp, 8191, SEEK_CUR); // this now works
- echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1+8191*2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement