Multiple instance method from Class Php Run Simuntanously

general-dev
objects

#1

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 :slight_smile:

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 :slight_smile:

for(var i = 0; i< 10; i++){

var active = new GET_PLAYLIST_IDs(param);

}

#2

Hi andrewtom19 welcome to the forum

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.


#3

hi ! Thanks for quick Rep !
So i have to wait it run sequential right ?
Is session can resole the problem ?

Although, if it run sequential, the execute time will take very long, I afraid gcloud will terminate it !
I have set php.ini is executation time is 0!


#4

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.


#5

oh thank for your info !
Maybe I learn NodeJs then ! Php is suck !


#6

If you want to download a lot of things in parallel I would recommend google go instead of NodeJS as it's much easier to learn.

Also PHP doesn't suck, it just doesn't fit this particular use case very well. Use the right tool for the job :slight_smile:


#7

thanks I don't want to download in parallel , It's just creating in parallel. Do you have any advise how can I achive that ?


#8

Well anything in parallel involving the network is where Google go really shines at, so I would still recommend that.

To get a sense of what that language looks like you can take their tour.


#9

thanks , I'll try that !


#10

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.