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

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

 



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