running Mozrepl with PHP ... - Joomla! Forum - community, help and support
as mozrepl creates server on port 4242, can connect via php , send commands it. small example given below can run command line.
what aimed:
well want fetch number of pages - thumbnails
well - can setup mozrepl perl , php too.
here snippets php
the following code sends 3 commands mozrepl server , prints responses.
again: aimed:
well want fetch number of pages - thumbnails
i have number of pages - stored in txt-file
example:
[php]www.google.com
www.altavista.com
www.yahoo.com
www.msm.com
www.oracle.com
[/php]
and on....
see sockethelper class dirt work
[php]<?php
require_once('sockethelper.php');
/* commands send mozrepl */
$commands=<<<eod
repl.whereami()
content.location.href = 'http://google.com'
repl.quit()
eod;
$firefox_socket = new sockethelper;
if(!$firefox_socket->connect()) exit;
foreach(explode("\n",$commands) $command){
if($command=='')continue; //skip blank lines
echo $firefox_socket->send_command($command);
}
?>
[/php]
the code sockethelper class
[php]
<?php
/* sockethelper.php */
class sockethelper
{
private $address = "127.0.0.1";
private $port = "4242";
private $socket = null;
public function connect()
{
$this->socket=socket_create(af_inet,sock_stream,sol_tcp);
if(!$this->socket){
socket_strerror($this->socket)."\n";
return false;
}
$result=socket_connect($this->socket,$this->address,$this->port);
if(!$result){
socket_strerror($result)."\n";
socket_close($this->socket);
return false;
}
$this->read();
return true;
}
/** send command mozrepl */
public function send_command($command){
$command.="\n";
socket_write($this->socket,$command);
return $this->read();
}
/*
read socket until "repl>" prompt,
or loop forever.
*/
private function read(){
$response = '';
while(1){
$chunk = socket_read($this->socket,65536,php_binary_read);
if($chunk === false){
echo "error reading socket\n";
break;
}
if($chunk === "") break; //no more data
if(preg_match('|^(.*)\s*repl\d*>\s*$|s',$chunk,$match)){
$response .= $match[1];
break;
}
$response .= $chunk;
}
return $response;
}
}
?>[/php]
any hint idea gather thumbmails?
what aimed:
well want fetch number of pages - thumbnails
well - can setup mozrepl perl , php too.
here snippets php
the following code sends 3 commands mozrepl server , prints responses.
again: aimed:
well want fetch number of pages - thumbnails
i have number of pages - stored in txt-file
example:
[php]www.google.com
www.altavista.com
www.yahoo.com
www.msm.com
www.oracle.com
[/php]
and on....
see sockethelper class dirt work
[php]<?php
require_once('sockethelper.php');
/* commands send mozrepl */
$commands=<<<eod
repl.whereami()
content.location.href = 'http://google.com'
repl.quit()
eod;
$firefox_socket = new sockethelper;
if(!$firefox_socket->connect()) exit;
foreach(explode("\n",$commands) $command){
if($command=='')continue; //skip blank lines
echo $firefox_socket->send_command($command);
}
?>
[/php]
the code sockethelper class
[php]
<?php
/* sockethelper.php */
class sockethelper
{
private $address = "127.0.0.1";
private $port = "4242";
private $socket = null;
public function connect()
{
$this->socket=socket_create(af_inet,sock_stream,sol_tcp);
if(!$this->socket){
socket_strerror($this->socket)."\n";
return false;
}
$result=socket_connect($this->socket,$this->address,$this->port);
if(!$result){
socket_strerror($result)."\n";
socket_close($this->socket);
return false;
}
$this->read();
return true;
}
/** send command mozrepl */
public function send_command($command){
$command.="\n";
socket_write($this->socket,$command);
return $this->read();
}
/*
read socket until "repl>" prompt,
or loop forever.
*/
private function read(){
$response = '';
while(1){
$chunk = socket_read($this->socket,65536,php_binary_read);
if($chunk === false){
echo "error reading socket\n";
break;
}
if($chunk === "") break; //no more data
if(preg_match('|^(.*)\s*repl\d*>\s*$|s',$chunk,$match)){
$response .= $match[1];
break;
}
$response .= $chunk;
}
return $response;
}
}
?>[/php]
any hint idea gather thumbmails?
Comments
Post a Comment