Re: I want to write a Multi-threaded PHP Application

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I forgot to put some final note into my last message.

PHP can be good for a lot of things, but not really for other. Wonder when requirements grow long in some ways you could not ever expect in a project like your's: A simple example: need 5 concurrent connections in your "hacked" multi-process server, that could be easily done in PHP, and, you could probably live with it in some circumstances. But do you wonder what could happen with your system if tomorrow you need to handle, let's say, 500 or 1000 concurrent connections? yeah, you will tell me that your software was not designed for that, or because PHP has no threading...

Having that in mind, you must think seriously about the future of your application, because switching today can save you a lot of time waste tomorrow, like happened to me with one project.

PHP was great for lots of projects I did, but if in the past I could only realize a bit of what I should have to do later, I definitely had switched immediatly before starting that developement, as I have done anyway later... the requirements for my applications grown more and gone far beyond what I ever expected... :-) but who knows that in advance?

I continue using PHP for a lot of tasks, tasks I know in the future won't requiere me to climb a mountain, being over its limits... because it was not the right tool to use for the job.

Hope my comments can help you in your thoughts of standarizing on a single codebase and language... :-)

Gonzalo


Gonzalo Monzón escribió:

D. Dante Lorenso escribió:

Gonzalo Monzón wrote:

Use Python, it is the way to go if you're willing to use mt  :-)



I've already written the multi-threaded server using Java. I want to do this in PHP, however, because the PHP "threads" can re-use PHP classes I've already written and hence standardize on a single codebase and language. Many other languages have threads (Java, C#, Python, Ruby, etc) ... which is why I'm so amazed PHP does not even list Threads as a priority. You simply can't be an enterprise language without these basic features. Of course, don't get me started on namespaces too ;-)

No, choosing a different language has been considered and I'd rather continue with my hacked multi-process PHP server solution before I am ready to change to a different language.

Dante


Sorry, but no PHP "threads" can re-use any PHP classes, as threads are not implemented yet... maybe until PHP 8 :-)

Threading isn't a trivial task, and if you MUST use it (I don't think so) you should develop some extension or take other approaches like embedding, and code all your threading needs apart from PHP, in C. But be careful interacting from that code to PHP. Or, perhaps switch to another language, if you can't cope with that.

I've been developing desktop applications with PHP-GTK since 2002, far beyond the web script context, and in the more complex projects I did, was a must to implement multi-process and IPC communication due to the lack of threading in PHP, as to deal with some issues like multiple tcp clients, multiple tcp server with a proxy to the application data, webservices, handling UI, and a lot more stuff, while doing "realtime" (the more realtime I was able of) processing of all incoming and outgoing data, for more than 24 hours long running time. Yes, I was able to be successful with such a developement after a lot of pain, but it is not likely the most common usage for PHP. I finally had to implement several parts in C, embedding PHP, and really, I was not happy of to cope with that, but I did not have the time to switch to another language as I had to re-use a lot of existing code that worked smooth with a multi-process approach, but without the need of so long running time, so many tcp clients, and so many data... I had to implement data containers in using C structures, as handling all that data from PHP taken more than 500Mb of RAM in no more than 8 hours of processing, interprocess syncronization mechanisms, and a lot more stuff.

In my case, multi threading was a real need I had to workaround. I think this is a real life example of PHP being expanded far beyond web paradigms or simple shell scripts, without any multi-threading support. But PHP is not thought in any case to be used for such applications... (I'm talking about desktop applications, not web script applications), with or without multithreading.

If you'd like to use mt in your applications or web scripts, better switch to some other language, or search for alternative ways of implementation as you did with a multi-process approach.

PHP its a great language, but it isn't the right tool for anything.

Gonzalo.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux