close this thread.
Printable View
close this thread.
Good luck with this!
Ah man, this would have been awesome! but in the end it will never be "stable". PHP is just a horrible language to write a server applications in. Use PHP for whats it is meant for, web applications.
Isn't this like the 4th thread of BloonPHP?
Good luck :-)
Just 1 old thread is for my old project (I recoded it from scratch)
@all : Thanks, I will upload SWF pack
- - - Updated - - -
In-game :
http://i.imgur.com/QCksqqp.png
Would be interesting to see any results of a stress test. Wonder how much it'll take.
socket_select($changed,$write,$except,NULL);
foreach($changed as $socket){
if($socket==$master){
}else{
Since it's only going to be the first in the array, I think it would be better to do
socket_select($changed,$write,$except,NULL);
if($changed[0] == $master){
master code
unset($changed[0]);
}
foreach($changed as $socket){
normal code
Otherwise you'd have a if/else 500 times (if you have 500 online users) that's not necessary
Good luck <3
I never said that, I said only the first item in the array has the potential to be the master, so checking on all of them (can be 500 if you have that many connections) would waste a lot of if/else checks
Another tip: If you're aiming for a high speed you should squeeze out every bit of performance you can and use as less overhead as possible. Use static so the pointer to the values doesn't have to be passed, pass strings and arrays as a pointer so they're not copied in memory, send buffers ASAP so you can reuse the memory and not get 1000 of buffers laying around. Also, you should find the best way to emulate "async" in PHP so you can send tasked packets to sockets that are still waiting for a potential send/receive. That was the part where I gave up because my implementation (async with suppressed socket async -> bool (false) means no data -> check for tasks). By that I mean for example a working pathfinder.
I hope your project goes well, if it does we might finally get a good working emulator across all OSes
PS: For is slightly faster than foreach :) NVM THIS
Well it isn't.
- http://stackoverflow.com/questions/3...foreach-in-php
- https://coderwall.com/p/il1tog
- http://m.metamorphosite.com/php-benc...ops-arrays#For
...and the list goes on
Did you pull that fact from your arse?
I never understood why people would make an emulator in PHP. Isn't something like C#/Java/C++/whatever much better?
Well, good luck with it.
I use PHP pthreads for multi-threading (just pathfinder for now) and I will use PHP APC for shared memory between all threads.
@azaidi : I don't need emulate "async", I use real posix multithreading with pthreads :thumbup:
If I remember Memcache is not stable for shared memory between 2 processes/thread because he overwrite old data when you write new data on memory
- - - Updated - - -
Demo for shared memory, working fine
http://i.imgur.com/knBY0zl.png
I recommend XCache, that's what i am using now. Replace all your apc_ with xcache_ and install the xcache module instead and you're good togo. It's offered as a replacement for APC, and works in the same way :-)
A suggestion would be a custom class so you can easily modify what cache module you want to use
For more information on XCache, checkout this post i wrote: http://forum.ragezone.com/f353/jonte...1/#post8030015Code:<?php
/**
* This exmaples uses xcache as caching module
* @author ZenLulz <me@zenlulz.com>
*/
class BloonCache {
// Maybe people prefer memcache, like Joopie. Well then we need to connect!
/*
private $obj;
function __construct($host, $port = 11211) {
$this->obj = new Memcache;
$this->obj->connect($host, $port);
}
*/
public function isset($name) {
return xcache_isset($name);
}
public function get($name) {
return $this->isset($name)?xcache_get($name):$name;
}
public function set($name, $value, $ttl = null) {
return xcache_set($name, $value, $ttl);
}
public function unset($name) {
return xcache_unset($name);
}
public function unset_by_prefix($prefix) {
return xcache_unset_by_prefix($prefix);
}
public function inc($name, $value = null, $ttl = null) {
return xcache_inc($name, $value, $ttl);
}
public function dec($name, $value = null, $ttl = null) {
return xcache_dec($name, $value, $ttl);
}
}
@ZenLulz Thanks I will test it :wink:
Anyone can give me shema of emulator threading ? (I don't know where I need use multithreading, database pooling ? Room ?)
Tutorial for Linux : http://pastebin.com/pZuZ9civ
Working fine
http://i.imgur.com/kPpm3IM.png
I need post update but I can't triple-post.. I stop post update about emulator, you can close this thread.