Hi guys, I have problem that want you guys to help me !
I want to loop to create multiple instance Class, then accessing member class (method) inside each instance. Each instance have own parameter I passed in, so the outcome of Member Class is diff that I want to achive.
The things is, It run sequential, I want all instance of method with diff parameter run at the same time (Simuntanously) . Here is the snippet of code
for($i = 0, $length = count($res) ; $i < $length; $i++){
$channel_Id = $res[$i][1];
//Get API Key to query
if(isset($dataDashboard[$row][3])){
$API_KEY = $dataDashboard[$row][3];
}
if($youtubeApiHelper->checkStatusChannel($API_KEY,$channel_Id) == false){ // If channel Live, then create!
$channel_code = $res[$i][0];
$youtube = $youtubeApiHelper->getYoutubeObject($channel_code,$dataDashboard); // get Youtube Object
//Create a object to Execute Copy Playlist
$createPlaylist = new Create_Playlist($youtube,$API_KEY,$channel_code);
// Return array list Id playlist
$createPlaylist->createPlaylist();
//sleep(10); // sleep for 10 sec then, move to next channel
} // end if - else
} // end Loop
It seem Javascript Class I can make it ! Like this Class :
var GET_PLAYLIST_IDs = function (form){
}
then I just Loop to create instance , all instance run at the same time
for(var i = 0; i< 10; i++){
var active = new GET_PLAYLIST_IDs(param);
}
It sounds like what you’re looking for is threading. However, AFAIK, unless you’re planning on running this from the command line, that option isn’t available.
Maybe you could use buffering? Although it wouldn’t be synchronization, it could delay the script until everything had finished.
Even then, it feels like a risky decision not only in terms of potentially heavy resource use, but in delays users may not feel are acceptable depending on what initiates the script.
I have no idea about gcloud, but I have a feeling they would not like tying up more resources for a shorter amount of time than they would like tying up a single resource for a longer time. Resource use is resource use.
Have you contacted them about what you want to do? I imagine they may offer a plan that would allow you to abuse resources to your hearts content as long as you were willing to pay for it. I’m fairly confident they won’t risk having your code negatively impact other of their customers. But if you are on your own isolated server they shouldn’t care if you push it to its limits.