Last active
December 16, 2015 14:09
-
-
Save iToto/5446526 to your computer and use it in GitHub Desktop.
pseudo batch loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$i = 0; | |
$rowsPerXMLFile = 50; | |
foreach ($dataFromDB as $key => $value) { | |
if ($i == 0 || $i % $rowsPerXMLFile > 0 ) { | |
$batch = '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" | |
xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:yt="http://gdata.youtube.com/schemas/2007"> | |
<batch:operation type="query" /> | |
<entry> | |
<id>http://gdata.youtube.com/feeds/api/videos/HSTdgmhGwgc?v=2</id> | |
</entry> | |
<entry> | |
<id>https://gdata.youtube.com/feeds/api/videos/jvBdaizgjxMQ?v=2</id> | |
</entry> | |
</feed>'; | |
} else { // at 50, lets curl | |
$ch = curl_init("http://gdata.youtube.com/feeds/api/videos/batch?v=2"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $batch); | |
$response = curl_exec($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
echo $httpCode, PHP_EOL; | |
$batch = ""; | |
} | |
$i++; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment