What is exec, and why do I need it?

First of all, the reason there are image optimization plugins is that PHP is bad at compressing images. If it were not so, someone would just write a nifty PHP function to compress your images, and we would all move on our merry way.

To optimize images, then, we need something outside of PHP. Most plugins simply send your images to a third-party server, run the optimization on their server, then send the image back. That much, PHP is great at. You can certainly do that with EWWW IO as well. In fact, I recommend it if you want to really make your site fast. Lossless compression will only get you so far, but lossy compression takes things to a whole different level.

But I digress, you wanted to know about exec, right? To optimize your images right on your own server, without sending them somewhere else, we still need some extra tools outside of PHP. EWWW I.O. uses tools like jpegtran, optipng, gifsicle, and others, but those are command-line tools, so how does PHP talk to a command-line tool? It uses one of several functions: system, passthru, or exec. The sole purpose of these functions is to allow PHP to run commands that you would normally run from the command-line on the server.

If you've seen a warning about exec() being disabled, you may wonder, "why would anyone disable exec?"

The simple answer is that exec can represent a security problem. It is very difficult to use the exec function correctly without opening up security holes. Thus many webhosts prefer not to trust random guys on the Internet to use exec correctly. Anything that is sent to the exec function needs to be sanitized, and escaped, and it isn't always easy to remember that. Indeed, it is something that I regularly have to check for in EWWW IO's code.

So, can you enable it? That depends greatly on your hosting environment. If you manage your own server, it is as simple as removing 'exec' from the disable_functions setting in your php.ini file. If you leave that arduous task to your webhost, then you cannot override it with a custom php.ini. If exec is disabled at the server level, the only one who can enable it is the "system administrator". In other words, you're at the mercy of your webhost here. Ask them, very nicely, if they will enable the exec function so that you can use the EWWW Image Optimizer to make your images smaller, use less space, and less bandwidth.

If you cannot enable exec, do not fret, EWWW IO can still make your images smaller, but we need to use the API to do so. Yes, it costs a little bit of money, but you get access to amazing technology from companies like JPEGmini and TinyPNG. And you get that access for far less than it would cost you if you purchased it directly. If you have any questions, we're always here to answer them. Happy Optimizing!

Still need help? Contact Us Contact Us