Is it possible in PHP to get a count of the number of bytes transmitted to the client? For example, if I'm outputting a 10 MB file, is there a way to find out if all 10 MB were sent to the client, or to see if the client interrupted the transfer partway? I know Apache will log this afterwards, but I'd like to access the data in PHP.
Take a look at the
Try setting a global variable prior to utilizing the class.
then use it to store the count and simply check it after your functions and classes have been called.
FTP will work, but:
If the server and the client are on the same network, you can use a network share. Going this route, you can use the normal filesystem functions available in PHP (docs). Just use the network name and share path, flip the slashes to forward: "//servername/path/to/share" Here is a tutorial on setting up a network share, assuming Windows is the client OS.
If network share is out of the question, you can set up a local FTP server. Here is a Lifehacker article on how to set this up, assuming you have a Windows OS. There are similar tutorials for Mac and *nix, there are so many you'd have to try NOT to find them on Google. :) There are many other routes to set up the FTP server, it isn't that important which server you use, just make sure you aren't leaving yourself wide open to the internet. After you set up the local FTP server, use PHP's FTP functions to connect from the server to your local machine.
It really is a better route to use the network share if you can, but of course that isn't an option if the server is not in your local network.
Yes, if you echo some data it will become part of whatever file you are sending and probably corrupt it.
I would recommend you look at the
error_log function. It will let you write to a log file, which won't affect output. You can look that the log periodically and check for any important errors.
Your server is already doing that, it is called the log file. If you grep it for the given page and count the number of log enteries, you will have the number of vistors who viewed that page. This, however, is inefficient and doesn't "work with CPanel".
Next, you could write a simple script to insert an entry to a database every time someone visits that page. Then your answer could be queried by custom PHP you add to CPanel. This is more effiecient, but would be reinventing the wheel.
But, the real answer is get analytics software. There are a number of products that can do this for you:
Piwik - This you can either get cloud-hosted, or host it yourself. It's free open-source software that does most of what Google Analytics does. You'd own your data and that data would reside on your server, there are widgets that could be embedded on pages so with some work could be integrated into CPanel. The reports are not as polished looking as Google Analytics, but that might be worth the trade-off.