Adding Multi-Threading to PHP (Purely New Idea Try it)

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Adding Multi-Threading to PHP (Purely New Idea Try it)

Post by ASDen »

I had an idea of Adding Multi-threading functionality to php ( i called it PHPThreader ) in little words the idea was :-
1. make a Js class which Creates Ajax Objects in order to call PHP Scripts(Threads)
2. then make a PHP class Implements and Interfaces the Js Class
3. Implement the PHP Class with your script easily and LAUNCH threads very easy Just Like:-
$obj=new Thread($filename,$Inputs); in other words:-
$e=new Thread("Download.php","url="http://www.phpfreaks.com");

you will find the Classes & Documentation & Examples at :-
http://sourceforge.net/project/showfile ... _id=532251
where

AjT.php : the Js Class which is implemented by the PHP class

Threader.php : PHP Class, which is a front to deal with the Js Class

Bag.php : is also dealing with Js Class to know the status of Thread( a finishing Alarm )

Examples contain :-
1.downloading 2 files in parallel .
2. a PDM (Php Download Manager) a simple download manager in php


Please tell me what do [s]u[/s] you think of the Idea & Implementation .Thanks in advance and waiting for [s]ur[/s] your critique
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Adding Multi-Threading to PHP (Purely New Idea Try it)

Post by timvw »

Notice that you're way after the original guy that had the same idea... And they're still laughing at us: just read viewtopic.php?t=72402....
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

Well ... laughing Gurus be known that I'm not a Newbie and i exactly know what is Multi-Threading
in your talk you run across mistakes and forget many of important Usages/features in Threading what about really interactive interfaces?
making full usage of your connection (download managers/multiple RSS readers)?
making real usage of the server processor?benefiting real threading abilities in Apache 2/IIS ?
and several to go with and you didn't suggest what is good for the post ? what is incorrect ? you JUST kept sending laughing posts showing exhibiting Bragging ...........
Here is the Critique :-
the img method is really innovative and i liked it's simplicity but it has some errors that's covered in my approach
1. it's interface Blocking and that is too bad as it may be doesn't block code but blocks interacting with user .
2. it's insecure as you offer the threads to user which is invoked with get (Dangerous) .
3. determining status isn't covered which is important in Multi-Threading .

If you JUST tries to understand my technique , download my classes and try them But why? you already have all programming in a capsule and FED up with all the trails of those Newbies

Thanks But Still I'm Sure in this Forum there is someone who cares , who is open minded in accepting new and to positively critique what is wrong
and encourage what is right .
Thanks again and Waiting for real technical Critique .
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I wanted to have a look at your documentation but it looks like I have to download and untar your code in order to see it. Do you have an online version of the documentation somewhere? No offence, but I only download code once I've seen whether or not it's worth downloading ;)

Can you comunicate between multiple threads or is each thread completely in a world of its own? Can you synchronize threads or do they just run like separate processes? That was mainly what I was interested in. If you can't do that then I'd just be using fsockopen() or pcntl_fork() to spawn new 'processes' in a dumb fashion :)

I'm open minded too... I'm always experimenting with new ideas but it doesn't strike me as possible to multithread in PHP... most people confuse running multiple *separate* processes with being equivalent to multithreading.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

PHP doesn't support multithreading.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

ASDen wrote:Well ... laughing Gurus be known that I'm not a Newbie and i exactly know what is Multi-Threading
And yet you insist on using the term multi-threading?
ASDen wrote:and forget many of important Usages/features in Threading what about really interactive interfaces?
Overhere php is mainly used for server-side scripting. Implementing really interactive interfaces with php is (imho) like riding a bike with flat tyres...

Just look at Bag.php:

Code: Select all

$f=fopen($_GET["num"],'wb');
For me this is typical 'newbie' code: No input validation, meaning that any file that is writeable for the account that executes can be truncated..
ASDen wrote: Here is the Critique :-
the img method is really innovative and i liked it's simplicity but it has some errors that's covered in my approach
1. it's interface Blocking and that is too bad as it may be doesn't block code but blocks interacting with user .
2. it's insecure as you offer the threads to user which is invoked with get (Dangerous) .
3. determining status isn't covered which is important in Multi-Threading .
4. The availability of 'multithreading' depends on the availability of an enabled javascript-engine on the http user-agent that is performing the request. If you invoke a php script via cron, multithreading wouldn't be available...
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

Well first thanks for all replies and yet we are all friends helping each other here :D
Second PHPThreader 1.1 (second version) is here http://sourceforge.net/project/showfile ... _id=203377

To d11wtq(what does this stand for anyway?): you said:-
I wanted to have a look at your documentation but it looks like I have to download and untar your code in order to see it
well may be the size is small but you have a point here and i fixed this as you will find in SF .
Can you comunicate between multiple threads
Yes . I added this Thanks for mentioning it. :D
Can you synchronize threads
Yes . I added this too - again Thanks for mentioning it - using a very simple Mutex Synchronization . :D

notice: the features above were added using a text file ,some string parsing and permissions for the Synchronization of data delivery .
fsockopen() or pcntl_fork() to spawn new 'processes' in a dumb fashion Smile
Please . in a straight manner tell me if it weren't for the features you asked for would you use this *dump* fashion instead of that Ease the class offered . You tell me :lol:
I'm open minded too... I'm always experimenting with new ideas
waiting for your comments and critique . but at ease make your words in a form more friendly *PLEASE*

To astions: you said:-

PHP doesn't support multithreading.
Yes , in a straight Forward Fashion . Speak more PLEASE .

To timvw: you said:-
And yet you insist on using the term multi-threading?
You bet
Overhere php is mainly used for server-side scripting. Implementing really interactive interfaces with php is (imho) like riding a bike with flat tyres...
well then you are the first one i see that hates extending/improving
and By The Way how did they let you write *imho* and hashed my u/ur
For me this is typical 'newbie' code
Well... First this is not commercial this is an Open Source script modify what you want and Second i'm proving an idea in this class this is a Pre-Release and the real *newbidity* is wasting time on validation and things like that here i mainly *make it work* after it works and the idea is proved i can get to these Time-Wasting things .... I know many of you may have a different opinion/view but Hey this my view and i'm totally open minded to hear yours

The availability of 'multithreading' depends on the availability of an enabled javascript-engine on the http user-agent that is performing the request
Well.... i think this point is out . As i think you ment that if the client doesn't enable a javascript-engine i can't do Ajax and hence nothing will happen well those clients who don't enable javascript-engine will not be able also to use Gmail , Google Maps ,Flicker .
you can deliver this notice to those *dumps* in Google
and PLEASE don't Say "You are not Google" Ajax is a revolution now which i CAN depend in it's existance

Many thanks to your interest and BE at ease make your words in a form more friendly *PLEASE*
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You cannot guarantee Javascript will be enabled. I don't use very many sites that require Javascript to run. This includes gmail and a LOT of Google's toys.

Javascript, by running on a client, should NEVER be required to help run server-based processes. I will not call them threads. They simply aren't. No matter how you try to twist their meaning, they aren't threads in this type of implementation.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

ASDen wrote:Well first thanks for all replies and yet we are all friends helping each other here :D
Second PHPThreader 1.1 (second version) is here http://sourceforge.net/project/showfile ... _id=203377
And the vulnerability is still there.
ASDen wrote:well then you are the first one i see that hates extending/improving and
I don't mind people extending/improving php, but for building 'really, really interactive interfaces' php is far from the best platform to do it with (But i could say that's true for any webbased platform) as this time...
ASDen wrote: the real *newbidity* is wasting time on validation and things like that here i mainly *make it work* after it works and the idea is proved i can get to these Time-Wasting things
I strongly disagree: Security is something that should be taken into consideration from the very beginning, certainly in a webenvironment...
ASDen wrote:
timvw wrote:The availability of 'multithreading' depends on the availability of an enabled javascript-engine on the http user-agent that is performing the request
Well.... i think this point is out . As i think you ment that if the client doesn't enable a javascript-engine i can't do Ajax and hence nothing will happen well those clients who don't enable javascript-engine will not be able also to use Gmail , Google Maps ,Flicker .
My point was that [s]most[/s] users of php-cli simply don't have a java-script engine..
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I still have to download a rar file to read the documentation? This is the point where I give up trying to learn more about your project ;)

Think about it from an end-user point of view. If you're looking for something to use in your project, what's the process you follow?

For me it's:

1. Search google, ask on forums
2. Visit project website
3. Find documentation and see if it's relevant
4. Download code, or go elsewhere

If I have to make a point of downloading a RAR file (not something that most operating systems can extract by default), unzipping it and then reading whatever document format you used (what format is it by the way?) then basically I'm just gonna go elsewhere.

Good luck with this project anyway :)
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

Well thanks for comments but i thought i'd hear roaring about ITC,Sync. but hopefully didn't :P

To feyd:- you said:-
I don't use very many sites that require Javascript to run. This includes gmail and a LOT of Google's toys.
well first let me ask you a question Do you use Js in YOUR sites?please don't say NO as this is - bearly - not an option and please guys shift from this point what would you have said if i used VBScript :!: :!:
one other thing i didn't like the term *Google toys* there aren't toys and if they are you can't imagine how big is the number of players (I'm sure you don't consider their search engine a toy otherwise i wouldn't have answered you as I'm sure then you play with US)

Javascript, by running on a client, should NEVER be required to help run server-based processes
Wellllll....... Ajax is already out there and have you heared of ThinWire .

I will not call them threads. They simply aren't. No matter how you try to twist their meaning, they aren't threads in this type of implementation.
well first i'm sticking to the big original dictionary definition of threads as the idea of Simultaneously , Interacting , Perfroming . and even let's take your point of view we are Mimicking tell me what's wrong in our mimicking technique ?
i do respect you but you didn't argue implementation you argued the idea itself well consider me Just a bad actor playing a the thread role in a play what was wrong? any ideas about fixing?but the refusal of the idea itself is a mistake read and then say toy are wrong AS:- 1. 2. 3.
many thanks to your interest and i'm waiting to hear a detailed critique from you espicially about the new features

To timvw:- you said:-
And the vulnerability is still there.
please mention these. please don't say the are using Ajax or the fopen issue :D

I don't mind people extending/improving php, but for building 'really, really interactive interfaces' php is far from the best platform to do it with (But i could say that's true for any webbased platform) as this time...
Well... Why? Why interactive interfaces aren't built in web-based platforms?
Ajax was a breakthrough in this exact point Interactivity . again i ask have you heared of ThinWire?
and i also mentioned dozens of things why hanging over this exact point ?
My point was that most users of php-cli simply don't have a java-script engine..
php-cli is this a joke or what ? we are webbing here
many thanks to your interest in the logic tell me about the new features

To d11wtq: you said:-
I still have to download a rar file to read the documentation? This is the point where I give up trying to learn more about your project
well.... no offense but let me say that what you said is unbearable. Mr here we are critiquing CODE not the project cover what will you lose if you downloaded the classes/documentation time(all Classes & Documentation & Examples is 17k) or you aren't willing at all again .Mr you say me the end-user point of view ARE YOU AN END USER ? :evil:
I have to make a point of downloading a RAR file
Well.. have you heared of 7-Zip it's an all in one Zipper with 27M downloads

But i have to thank you for reminding me with the ITC/Sync. issue . and i hope I'll hear from you again
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I think the closest you can get to multithreading in PHP is to use CLI scripts that can communicate with each other via memcache; and even then, that still isn't optimal.
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

I think the closest you can get to multithreading in PHP is to use CLI scripts
And then ? if you practiced Multi-Threading in php-cli what is the benefits Desktop languages already have multi-threading centuries ago
do you really think PHP is going to face (Java/C/C++ or even VB) in Desktop applications ..... not a chance
the power of php is exploited in web applications as a server side scripting language and this specific Job is enhanced using Multi-Threading .
Thanks for your reply .But i want you to tell me of Real application - you think - can benefit from the class .
Thanks in advance .
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post by Z3RO21 »

ASDen wrote:the real *newbidity* is wasting time on validation and things like that here i mainly *make it work* after it works and the idea is proved i can get to these Time-Wasting things ....
Wow if this is your view I would never use your application. And you should not think all users will have javascript or require them to. If you do use javascript make sure there is a way it can be done without javascript. Remember your making the application for the user so don't cater to your needs cater to theirs because in the end they are the audience.
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

Wow if this is your view I would never use your application
well as an end user i don't encourage you any way not now i'm testing it now and developing basis and i didn't get to validation and input reviewal
If you do use javascript make sure there is a way it can be done without javascript
This is really a Joke .... if i knew another way of implementing it without Js why would i implement it in Js in the first place

Thanks to your concern
Post Reply