php - How to define timeout for copy image from server -


i need copy image server in order create different types of images it, e.g. thumbnail.

while works ok imagecreatefromjpeg($picture_location); create problem if image not available , take 30s timeout.

therefore thought downloading first copy:

copy('http://www.server.com/file.jpg', '/tmp/file.jpeg'); 

unfortunatelly there no way decrease timeout if connect fails or image has been removed.

is there better way achieve intending? thank on this.

you can download file via curl has timeout option.

<?php  $fp = fopen (dirname(__file__) . '/localfile.tmp', 'w+'); $ch = curl_init($url); curl_setopt($ch, curlopt_timeout, 50); //timeout curl_setopt($ch, curlopt_file, $fp);  curl_setopt($ch, curlopt_followlocation, true); curl_exec($ch); curl_close($ch); fclose($fp); ?> 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -