If you smush large image (eg. over 900KB), you can get error "Operation timed out after 5000 milliseconds with 0 bytes received". Problem is that WordPress by default timeouts after 5 seconds while doing HTTP requests.
To fix this issue we need to simply add filter which increases timeout period.
First we need function:
function wp_smushit_filter_timeout_time($time) {
$time = 25; //new number of seconds
return $time;
}
Then we need to call this function via add_filter. I added this in function wp_smushit_post below $data = false; so that this filter is used only in WP smush.it:
add_filter( 'http_request_timeout', 'wp_smushit_filter_timeout_time');
Another thing to consider would be adding of function set_time_limit which would increase time script runs. It can be added above $data = wp_smushit_post($file_url);.