Some cool and little known PHP functions / features

  1. register_shutdown_function
    Recently I was building a PHP based load balancer for handling long running (video streams, sometimes up to 1 hour) processes. My biggest problem were if the user closed the page the load balancer had to react. This handy function is the best solution for the problem. Basically it calls the callback function when the script’s execution finishes or the user closes the browser window
  2. scandir
    If you are tired of using opendir, readdir and closedir, this function is for you
  3. glob
    Even better than scandir. It will only list the files matching the pattern passed in as an argument
  4. CURLOPT_PROGRESSFUNCTION
    This is a fairly new feature of the curl library. You can specify a callback function which will be executed every time a chunk of data comes back from the remote host. Usually I’m using it to create progress bars for long running curl processes
  5. escapeshellcmd
    I’m dealing with loads of user generated files in many different languages. As you may know the golden rule: “Users are idiots” so they put spaces, quotes and many many random characters in the file names. escapeshellcmd is a really handy function to escape a command before you call exec
Be Sociable, Share!

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">