I was having the exactly the same issue. I was first storing the image data on a local HDD before using the function imagecreatefromjpeg() to post-process the image further.
At certain times the locally stored image was corrupted during the store process and when called by imagecreatefromjpeg($imagePath); the PHP Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file occured. showed up.
So to resolve the PHP warnings and to make up for the corrupted image I used a clearly defined solution in the PHP manual (http://php.net/manual/en/function.imagecreatefromjpeg.php) see the function LoadJpeg($imgname)
To prevent the further failures I have focused on the reason why the data supplied to imagecreatefromjpeg() function was not integrious in the first place. In my case it was the network flood issue which was causing some images to arrive corrupted.
Long story short, you may want to check what exactly is being supplied into imagecreatefromjpeg() function before trying to extend the base library etc..