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

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

Post by ASDen »

1. Get it to work without javascript.
2. Get it to work without a browser. (CLI Version)
Why This Easy Stuff ?
I'm getting it to work without an Internet Connection .


Anyway have you tested it?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

ASDen, whenever somebody tells you that this is not multi-threading, you simply repeat that it is and that this has been stated before. You still have not explained how this is in any way multi-threading. Would you please just admit that what you are doing is not multi-threading or explain to us what detail we're all missing. Many (if not all) of the most knowledgeable members on this forum have explained (some of them several times) to you that this is not multi-threading and that what you are doing could be accomplished better, and less nonsensically with fsockopen. Using javascript for this provides no benefits that I can see. Please explain to me how this will benefit my application in any way.

Also, don't tell me to read the whole thread because I did.
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

astions wrote:
ASDen wrote:challenging requests
1. Get it to work without javascript.
2. Get it to work without a browser. (CLI Version)
Threading is not possible with PHP CLI but you can achieve similar results by using Unix style forking: http://au2.php.net/manual/en/ref.pcntl.php
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

ASDen wrote:
1. Get it to work without javascript.
2. Get it to work without a browser. (CLI Version)
Why This Easy Stuff ?
I'm getting it to work without an Internet Connection .
lmao

but seriously code gave me bunch of js errors...
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

To The Ninja Space Goat:-
Would you please just admit that what you are doing is not multi-threading or explain to us what detail we're all missing
what I'm doing here is providing Multi-Threading functionality to an environment which doesn't support it of course it's not like Threading in C or Java but to quite an extent it do the job with features:-
1. Performing at the same time
2. communication between threads
3. Providing Synchronization of data delivered in all threads
4. Provided a process object that holds the threads communicating directly with each other
5. Providing a direct communication between user and threads (Threads can give orders Through Js to browser)
Most of these Features were used in the Jsim example (except the process notion added later)
( I slitted the reply look below)
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

what you are doing could be accomplished better, and less nonsensically with fsockopen
That's not true as for the following reasons :-
1.The Cpu load :- using sockets will result in a high server cpu load (especially for high client number) compared to using this class as the load is shared between the Server and the Client
2.Connectivity to user :- when using the class the threads is connected Directley to the user through a Js function (ChangeBag)
3. Memory Load :-using sockets from the server to it self will make to pay for all the memory cost (it opens the page handles both way connections)
4. Availability :- fsockopen() and sockets in general is banned in a good deal of free hosting services (Good Experienced ones Esp.) and this is due to - as i think - bandwidth bleeding application based on it and the functionality they offer and i really think that nearly it will be banned in all free hosts and a number of low-paid hosting while Ajax case is client dependent which is a good point
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

Please explain to me how this will benefit my application in any way.
in a numerous number of ways :-
1. Building really interactive interfaces
2. making real usage of the server processor (Focus on this point)
3. making full usage of your connection (download managers/multiple RSS readers) [And this point also]
4. benefiting real threading abilities in Apache 2/IIS
At last really thanks to your Unbiased attitude
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

To n00b Saibot :-
but seriously code gave me bunch of js errors...

do you use the link Or the code itself?
in what browser ?
what are these errors?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

ASDen wrote:do you use the link Or the code itself?
Your provided link :arrow: http://7zone1.110mb.com/Jsim.php
ASDen wrote:in what browser ?
XP SP2, IE7
ASDen wrote:what are these errors?
IE7 wrote:Error[Line 56]: The data necessary to complete this operation is not yet available.
Relevant Code:

Code: Select all

function ChangeBag()
{


// all requests go here so it's our bag and here telling bag script if a thread finished

for (var x=0;x<i;x++)

{

if (t[x].request.readyState >= 3 && t[x].Tnum!=-1)

{
eval(t[x].request.responseText);   // <--- HERE
//alert(t[x].request.responseText);
//t[x].Tnum=-1;
}
}
}
Error repeated atleast three times before i got to see the `10`...

I won't argue about Multi-threading vs. Multi-Tasking since that of no use... but atleast you can aim towards cross-browser compatibility & exact functioning under all possible circumstances...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I get an empty page with this error repeating,

Code: Select all

Error: syntax error
Source File: http://7zone1.110mb.com/AjT.js
Line: 56, Column: 134
Source Code:
var d = new Date();document.getElementById("M").innerHTML="1";var d = new Date();document.getElementById("M").innerHTML="2";var d = new
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

You have some coding errors:

Code: Select all

<br />

<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in <b>/www/110mb.com/7/z

/o/n/e/1/_/_/7zone1/htdocs/ThreadComHelper.php</b> on line <b>59</b><br />

<br />

<b>Warning</b>:  fclose(): supplied argument is not a valid stream resource in <b>/www/110mb.com/7/z

/o/n/e/1/_/_/7zone1/htdocs/ThreadComHelper.php</b> on line <b>60</b><br />
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

jeffery wrote:You have some coding errors:

Code: Select all

<br />

<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in <b>/www/110mb.com/7/z

/o/n/e/1/_/_/7zone1/htdocs/ThreadComHelper.php</b> on line <b>59</b><br />

<br />

<b>Warning</b>:  fclose(): supplied argument is not a valid stream resource in <b>/www/110mb.com/7/z

/o/n/e/1/_/_/7zone1/htdocs/ThreadComHelper.php</b> on line <b>60</b><br />
I suspect you just need to make the directory writable, although some error checking would be good.
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

To n00b Saibot:-
Error[Line 56]: The data necessary to complete this operation is not yet available.
I tried it in IE7 it said there are errors-like-IE6 but didn't interrupt
atleast you can aim towards cross-browser compatibility & exact functioning under all possible circumstances...
I want to say two things:-
1. cross-browser is only in displaying issues but in case of Performing browser has no effect
2. ALL the problem is FF is the only browser - i tried - that implements Ajax as it should and IE is the most one who volatile it Especially it requires to get the whole page to load in screen which rises Previous errors (ignored in safari/opera)
To Jcart :-
I get an empty page with this error repeating,
Weired thing Details about browser Please .
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post by ASDen »

To jeffery & d11wtq :-
The problems are things in code i left as it doesn't affect viewer it just requires what d11wtq said or just a @ just for good looking to FireBug users :D
To The Ninja Space Goat:-
Did you vanish Or you just wanted to ask ?
---------------------------------------------------------
I have something i want to hear from all of you about
i finished another communication memory that uses Memory not files in a more optimized way for Access , Synchronization , simpler code BUT -as you can guess - it requires something that is not available to all hosts well let's make it a speed-optimized alternative
I use MySql Heap Engine/Table so the problem is MySql is required but it benefits what i said
What do you all think ?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

ASDen wrote:ALL the problem is FF is the only browser - i tried - that implements Ajax as it should and IE is the most one who volatile it
Then I am sorry to say, but if you are coding something for public use then you have to do some defensive coding to get around it...
Secondly, IE7 supports XHR object natively...


lastly, word is `violate` instead of `volatile`....
Post Reply