I've gone more in the abstract class idea and provided one also for calling the threads this made it very easy to implement the Sockets idea with no miss up and maintain good binding of the code (i haven't uploaded yet to SF for any suggestions of you first ) .
Code: Select all
<?php
/*Author :ASDen(Mohammed Yousef)
Country:Egypt
Email :harrrrpo@gmail.com
Email me for any help or just encourage me and tell me it does work !
The PHP Class implementing the Js Class */
require "Caller.php";
class SocThread extends CallerBasic
{
private $Host;
private $params;
function __construct($url,$params,$MothProcess)
{
CallerBasic::__construct($url,$params,$MothProcess);
$this->Host=$url;
$this->params=$params;
}
function Go()
{
$ar=Parse_url($this->Host);
$HostQ=$ar['host'];
$URI=$ar["path"];
$ReqBody=$this->params;
$ContentLength=strlen($ReqBody);
$ReqHeader =
"POST $URI HTTP/1.1\n".
"Host: $HostQ\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $ContentLength\n\n".
"$ReqBody\n".
//"Connection: close\n";
$socket = fsockopen($HostQ, 80, &$errno, &$errstr);
fputs($socket, $ReqHeader);
fclose($socket);
}
}
?>
I tested the Ajax Implementation vs. the Sockets Implementations in Win xp ( FF & Opera & IE & Safari ) the
Results :-
the thread used for testing is a simple one
Code: Select all
<?php
sleep(2);
$f=fopen($_POST["P"],"w");
?>
And it was called
1000 times :-
Memory :
Sockets : Apache process used Memory raised 150M
Ajax : Apache process used Memory raised ~4M
Speed:
Sockets were of course Much faster but there server load was severe
one thing also to note is the high CPU Usage of client (browser) in Ajax Method :-
FF : 50%
Opera :started at 50% but went down steadily to 20%~25%
Safari :Amazingly started at 5%~6% ending in about 12% (But slower than others)
IE :Behaved strangely first it's memory usage rose 150M with a cpu usage of 1~2% then dropped down 130M and cpu usage rised to
50% after that the execution stopped without finishing/calling all threads (~300 only)
of course in Sockets case non of this happened as full load is on server
I'd like to hear from u About Results & should i add sockets approach or not