Cyberslime Posted May 10, 2009 Share Posted May 10, 2009 So what I want to do is something like this: for ( $socknumber = 1; $socknumber <= 20; $socknumber += 1) { $sck = fsockopen ($site, 80, $errno, $errstr, 30); } But in the $sck variable I want it to have an identifier like: $sck($socknumber) = fso.... How can I do this? Link to comment https://forums.phpfreaks.com/topic/157623-multiple-socket-creation-loop/ Share on other sites More sharing options...
Cyberslime Posted May 10, 2009 Author Share Posted May 10, 2009 sorry bout the double post but answer plz, it's really important and urgent Link to comment https://forums.phpfreaks.com/topic/157623-multiple-socket-creation-loop/#findComment-831168 Share on other sites More sharing options...
Andy-H Posted May 10, 2009 Share Posted May 10, 2009 You can use an array, for ( $socknumber = 1; $socknumber <= 20; $socknumber += 1) { $sck[] = fsockopen ($site, 80, $errno, $errstr, 30); } /* Then access them using foreach() */ foreach($sck As $socket) { // Do something with $socket } Link to comment https://forums.phpfreaks.com/topic/157623-multiple-socket-creation-loop/#findComment-831171 Share on other sites More sharing options...
Cyberslime Posted May 10, 2009 Author Share Posted May 10, 2009 Thanks. Oh another thing, is ther a solution = to goto for older versions of php? Link to comment https://forums.phpfreaks.com/topic/157623-multiple-socket-creation-loop/#findComment-831176 Share on other sites More sharing options...
Andy-H Posted May 10, 2009 Share Posted May 10, 2009 As far as I know goto is only availible since PHP 5.3. If / else / elseif statements should be easy enough to replicate the functionality. Or switch statements with multiple actions for each case perhaps? Link to comment https://forums.phpfreaks.com/topic/157623-multiple-socket-creation-loop/#findComment-831177 Share on other sites More sharing options...
Cyberslime Posted May 11, 2009 Author Share Posted May 11, 2009 I'm not being able to put it to work, can you leave an example that starts 5 sockets and then sends data with them? I'd also like to loop the data sending infinite times. Example: Socket 1 sends 1, socket 2 sends 2, socket 3 => 3, sock 4 => 4, sock 5 => 5 Data received by server: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 etc... Link to comment https://forums.phpfreaks.com/topic/157623-multiple-socket-creation-loop/#findComment-831735 Share on other sites More sharing options...
Cyberslime Posted May 11, 2009 Author Share Posted May 11, 2009 help me.... x) Link to comment https://forums.phpfreaks.com/topic/157623-multiple-socket-creation-loop/#findComment-831819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.