Je me suis tué toute la journée pour ce seul bug. Je ne peux pas vous dire à quel point j'apprécierais toute aide possible à ce sujet.Impossible de définir CURLOPT_NOBODY sans planter curl_exec
Fondamentalement, j'ai un script très simple. Il se connecte à un site Web, examine l'en-tête d'un fichier pour voir s'il s'agit d'un type d'image, puis le télécharge. Il répète ensuite cela trois fois.
Le problème ici est que je ne peux pas définir CURLOPT_NOBODY sans que curl_exec plante l'ensemble du script avec des erreurs -no-. (Je ne peux même pas appeler ou obtenir un curl_error!) Il semblerait qu'il m'est impossible d'aller de CURLOPT_NOBODY, vrai à CURLOPT_NOBODY, faux. La boucle ci-dessous s'exécute une fois puis meurt().
Qu'est-ce qui pourrait causer ce bug?
Voici le script:
// Log into the Website
curl_setopt($ch, CURLOPT_URL, 'http://myexample.com/login');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_exec($ch);
// Begin the Loop for Finding Images
for($i = 0; $i < 3; $i++) {
curl_setopt($ch, CURLOPT_URL, 'http://myexample.com/file.php?id=' . $i);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$output = curl_exec($ch) or die('WHY DOES THIS DIE!!!');
$curl_info = curl_getinfo($ch);
echo '<br/>' . $output;
// (Normally checks for content type here) Download the File
curl_setopt($ch, CURLOPT_URL, 'http://myexample.com/file.php?id=' . $i);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
$filename = 'downloads/test-' . $i . '.jpg';
$fp = fopen($filename, 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
fclose($fp);
}
Je suis en cours d'exécution apache 2.2 et la version PHP 5.2.13. Merci pour toute aide- je ne peux pas vous dire combien je l'apprécierais. Je suis complètement coincé ici. :(
I lo ve vous. Je fais vraiment. Merci beaucoup! Ce bug avait absolument gâché ma semaine. J'avais jeté des heures et des heures à essayer de trouver ce qui le causait sans chance, des sorties aléatoires, et aucun message d'erreur. Ici, je utilisais curl complètement faux! Sachez que vous avez fait quelqu'un très, très heureux ici! Merci encore :) – tsp3