Async Sockets in PHP (Good for a PHP Emulator base)

Results 1 to 21 of 21
  1. #1
    I don't even know azaidi is offline
    MemberRank
    Apr 2010 Join Date
    the NetherlandsLocation
    2,065Posts

    Async Sockets in PHP (Good for a PHP Emulator base)

    I've been working on this for a long time. It wasn't very hard to make, but it's hard to understand how this works. Sometimes I even didn't understand my own code anymore. But it works

    I've released the MultiThreadSimulation Emulator base some time ago, which already had a "Calls" system. I found out with that system you have so much possibilities in PHP. Even more than C# because PHP doesn't have type checks (int, string etc).

    What is this?

    This has a much better version of the "Calls" system, which I now call Threads (Although in C# they are different). I made an AsyncSockets TcpSocket class based on this. Just look in it and you'll see what I mean

    How does this work?

    You first have to understand "threads" from other languages, for example C#. The C# code is converted to OpCodes, which you can see in Reflector with Reflexil. Those codes are converted to other level codes, but it's about those opcodes now. PHP is a single threaded language, which converts PHP Code to a list of opcodes and runs them. Now threading is the switching of those list.

    PHP:

    Thread 1:
    Opcode1
    Opcode2
    Opcode3
    Opcode4
    Opcode5
    Opcode6

    It runs the 6 opcodes

    Now MultiThreading in C# works like this:

    Thread 1:
    Opcode1
    Opcode3
    Opcode5

    Thread 2:
    Opcode2
    Opcode4
    Opcode6

    These 2 threads are combined into one list opcodes (1, 2, 3, 4, 5, 6)

    Do you understand how multithreading works now? You have a list of threads, then from all the threads one opcode is ran.

    Now my system in PHP works like this: the "threads" are list with functions. It switches all those threads and runs one function. You shouldn't call functions directly from another function, but add it to the threads list so it is ran when it is the turn of the thread.

    I based my sockets on this by adding a function to the "functions" list, for example with receiving, every time there is no data to check if there is data.

    If you really want to understand it please look into my code.

    Download Link: Async Sockets in PHP.rar

    Now please make a PHP emulator with this . I'm not going to continue my MS (MultiThread Simulation) Emulator because I don't have time for it. When I have more time I might go back to Emulators but with all the shit going on about the new crypto and the new CEO who might change Habbo I don't want to make an Emulator.


  2. #2
    Alpha Member Emily is offline
    MemberRank
    Oct 2012 Join Date
    The NetherlandsLocation
    2,408Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    An emulator coded in PHP isn't a good idea.. especially when you want it to be something like Habbo (it could be good for Jabbo-based ideas)
    Anyways, I guess nice release

  3. #3
    I don't even know azaidi is offline
    MemberRank
    Apr 2010 Join Date
    the NetherlandsLocation
    2,065Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by Tha View Post
    An emulator coded in PHP isn't a good idea.. especially when you want it to be something like Habbo (it could be good for Jabbo-based ideas)
    Anyways, I guess nice release
    PHP really has a lot of possibilities because you don't need to convert every type. And these sockets should be able to handle at least 50 people online I think.

  4. #4
    Live Ocottish Sverlord Joopie is offline
    LegendRank
    Jun 2010 Join Date
    The NetherlandsLocation
    2,773Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by Tha View Post
    An emulator coded in PHP isn't a good idea.. especially when you want it to be something like Habbo (it could be good for Jabbo-based ideas)
    Anyways, I guess nice release
    HipHop by facebook can convert PHP to C++. And why do you want something like Habbo? running an public hotel is already illegal. People MAY hobby around with this shit and continue it. Just for fun. That's where it's all about, isn't?

  5. #5
    No, Just no. Matthew is offline
    MemberRank
    Jul 2008 Join Date
    United KingdomLocation
    1,408Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by azaidi View Post
    PHP really has a lot of possibilities because you don't need to convert every type.
    No. That just encourages lazy programming in the real world.

  6. #6
    Lurking since '06 1ntel is offline
    MemberRank
    Jul 2006 Join Date
    401Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    deleted
    Last edited by 1ntel; 30-04-13 at 09:34 PM.

  7. #7
    Alpha Member Emily is offline
    MemberRank
    Oct 2012 Join Date
    The NetherlandsLocation
    2,408Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by joopie View Post
    HipHop by facebook can convert PHP to C++. And why do you want something like Habbo? running an public hotel is already illegal. People MAY hobby around with this shit and continue it. Just for fun. That's where it's all about, isn't?
    If this is not for Habbo emulators, why is it released here?
    It says it's a base for PHP Emulators, and I said tbh in my opinion PHP emulator isn't good for working same method as Butterfly and Phoenix does (with a flash client) because I think it won't be able to handle 100+ connections (so it isn't very useful in my opinion)

  8. #8
    Occasional Visitor Cecer is offline
    MemberRank
    Aug 2006 Join Date
    EnglandLocation
    743Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by azaidi View Post
    You first have to understand "threads" from other languages, for example C#. The C# code is converted to OpCodes, which you can see in Reflector with Reflexil. Those codes are converted to other level codes, but it's about those opcodes now. PHP is a single threaded language, which converts PHP Code to a list of opcodes and runs them. Now threading is the switching of those list.

    PHP:

    Thread 1:
    Opcode1
    Opcode2
    Opcode3
    Opcode4
    Opcode5
    Opcode6

    It runs the 6 opcodes

    Now MultiThreading in C# works like this:

    Thread 1:
    Opcode1
    Opcode3
    Opcode5

    Thread 2:
    Opcode2
    Opcode4
    Opcode6

    These 2 threads are combined into one list opcodes (1, 2, 3, 4, 5, 6)

    Do you understand how multithreading works now? You have a list of threads, then from all the threads one opcode is ran.
    Eh.. no.
    Threads in .NET use threads at the operating system level. These separate threads will be shared across the CPU cores by the OS.

    PHP has no real OS level threading support and therefore the best you can really get would be multiple lines of execution being shared on a single core.

    In theory you could have multiple PHP files execute in parallel and somehow get them to work with each other. Either way you still end up with an utter mess in an already messy language.

    Worth a read: PHP: a fractal of bad design - fuzzy notepad

  9. #9
    Live Ocottish Sverlord Joopie is offline
    LegendRank
    Jun 2010 Join Date
    The NetherlandsLocation
    2,773Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by cecer1 View Post
    Eh.. no.
    Threads in .NET use threads at the operating system level. These separate threads will be shared across the CPU cores by the OS.

    PHP has no real OS level threading support and therefore the best you can really get would be multiple lines of execution being shared on a single core.

    In theory you could have multiple PHP files execute in parallel and somehow get them to work with each other. Either way you still end up with an utter mess in an already messy language.

    Worth a read: PHP: a fractal of bad design - fuzzy notepad
    Well, I have to agree with all of that LOL..

    And I lol'd about this: "More recently, PHP 5.3.7 managed to include a crypt() function that would, in effect, let anyone log in with any password."

    But most of the webhost only support PHP as program languages because it's widely used.

  10. #10
    I don't even know azaidi is offline
    MemberRank
    Apr 2010 Join Date
    the NetherlandsLocation
    2,065Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by cecer1 View Post
    Eh.. no.
    Threads in .NET use threads at the operating system level. These separate threads will be shared across the CPU cores by the OS.

    PHP has no real OS level threading support and therefore the best you can really get would be multiple lines of execution being shared on a single core.

    In theory you could have multiple PHP files execute in parallel and somehow get them to work with each other. Either way you still end up with an utter mess in an already messy language.

    Worth a read: PHP: a fractal of bad design - fuzzy notepad
    Thanks
    __

    I should've written this in brainfuck..
    Last edited by azaidi; 13-01-13 at 09:57 PM.

  11. #11
    "(still lacks brains)" NoBrain is offline
    MemberRank
    Sep 2011 Join Date
    United KingdomLocation
    2,658Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    A PHP emulator? We've already seen this happen and it clearly wasn't stable. PHP is built for web applications and not servers.

  12. #12
    I don't even know azaidi is offline
    MemberRank
    Apr 2010 Join Date
    the NetherlandsLocation
    2,065Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by ησвяαιη View Post
    A PHP emulator? We've already seen this happen and it clearly wasn't stable. PHP is built for web applications and not servers.
    First look in the source then comment.

  13. #13
    Custom Title Enabled James is offline
    LegendRank
    Jan 2007 Join Date
    DenverLocation
    2,288Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by azaidi View Post
    First look in the source then comment.
    The source won't help anything, how will you handle more than one thing at once? It's gonna' get hairy trying to code so many things in PHP. C# has threading, in php you'll need to fork a child process, just take the time and learn Java or C#, both are derived from c, it won't take you long to pick up the syntax, it's really similar.

  14. #14
    son, i am dissapoint Near is offline
    MemberRank
    Sep 2009 Join Date
    The NetherlandsLocation
    491Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by James View Post
    The source won't help anything, how will you handle more than one thing at once? It's gonna' get hairy trying to code so many things in PHP. C# has threading, in php you'll need to fork a child process, just take the time and learn Java or C#, both are derived from c, it won't take you long to pick up the syntax, it's really similar.
    Well, Java/C# will be harder if you've never touched OOP though. But yeah, learning Java/C# is more fun too! OO is way more interesting then simply scripting.

  15. #15
    Alpha Member Moogly is offline
    MemberRank
    Feb 2008 Join Date
    Pool LidoLocation
    2,322Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by joopie View Post
    HipHop by facebook can convert PHP to C++. And why do you want something like Habbo? running an public hotel is already illegal. People MAY hobby around with this shit and continue it. Just for fun. That's where it's all about, isn't?
    There's also Phalanger which I recommend anyone trying to code an Emulator in PHP not to use the standard PHP if they think they can use it for a "hotel" or it will crash and burn. You're better off coding it in that ugly mother language to PHP called Perl. If you want a serious PHP server or to extend a C# Emulator with PHP code check out Phalanger:

    Phalanger - The PHP Language Compiler for the .NET Framework - Home

    It let's you compile your PHP into .NET and work with .NET projects. You could in theory re-code half of Butterfly in pure PHP code, although that would be awful that's just one possibility.

  16. #16
    I don't even know azaidi is offline
    MemberRank
    Apr 2010 Join Date
    the NetherlandsLocation
    2,065Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Seriously I already know C# but I think there should be atleast 1 PHP Emulator because it's cross-platform.

  17. #17
    Lurking since '06 1ntel is offline
    MemberRank
    Jul 2006 Join Date
    401Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by azaidi View Post
    Seriously I already know C# but I think there should be atleast 1 PHP Emulator because it's cross-platform.
    Just stop right here now and don't even waste your time with a "PHP Emulator" .. :S
    Last edited by 1ntel; 15-01-13 at 03:41 PM.

  18. #18
    "(still lacks brains)" NoBrain is offline
    MemberRank
    Sep 2011 Join Date
    United KingdomLocation
    2,658Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by azaidi View Post
    Seriously I already know C# but I think there should be atleast 1 PHP Emulator because it's cross-platform.
    C# can be cross-platform...

  19. #19
    Alpha Member Moogly is offline
    MemberRank
    Feb 2008 Join Date
    Pool LidoLocation
    2,322Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by azaidi View Post
    Seriously I already know C# but I think there should be atleast 1 PHP Emulator because it's cross-platform.
    You didn't read anything I said clearly.

  20. #20
    Run, but I'll find you. Ddos Attack is offline
    MemberRank
    Jan 2011 Join Date
    AustraliaLocation
    908Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by James View Post
    The source won't help anything, how will you handle more than one thing at once? It's gonna' get hairy trying to code so many things in PHP. C# has threading, in php you'll need to fork a child process, just take the time and learn Java or C#, both are derived from c, it won't take you long to pick up the syntax, it's really similar.
    Totally agree with you there!
    Starting learning C# the day BcStorm came out, and I already created a minor fix ;P
    I had PHP experience though.

  21. #21
    I don't even know azaidi is offline
    MemberRank
    Apr 2010 Join Date
    the NetherlandsLocation
    2,065Posts

    Re: Async Sockets in PHP (Good for a PHP Emulator base)

    Quote Originally Posted by Moogly View Post
    You didn't read anything I said clearly.
    Sorry I didn't read your post :p, but James said I should learn C#. I made my Phoenix crack, the emulator proxy, and some more tools for teamhotel in C#.



Advertisement