I am creating an application that at some point twists the content from an external URL. Until now, it always ended pretty quickly / instantly. However, I'm not sure what will happen if the external server takes a long time to respond. Will PHP wait to execute the following code until cURL completes?
I cannot verify this because I do not know how to "simulate" a slower answer. I hope this pseudo code makes my question clear:
$ch = curl_init( $some_remote_url ); $fp = fopen( $some_local_file, 'wb' ); curl_setopt( $ch, CURLOPT_FILE, $fp ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_exec( $ch ); // Let say this takes 20 seconds until the other server responds curl_close( $ch ); fclose( $fp ); redirect( $some_other_url ); // Will this be executed instantly or only after 20 seconds?
The reason I'm curious is because I don't want my user to look at the download page for 20 seconds if the remote server is slow to respond, so I probably have to move the whole process to a cron job. The user does not need the result of twisting instantly, so it does not matter for him when the process is completed.
Louis B.
source share