PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 9th, 2012, 10:31 AM
metabo metabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 229 metabo Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 14 h 19 m 9 sec
Reputation Power: 0
Running Mozrepl with PHP .... some last questions

As MozRepl creates a server on port 4242, we can easily connect to it via PHP and send commands to it. A small example is given below which you we can run from the command line.

what is aimed:

well i want to fetch a number of pages - as thumbnails
well - we can setup MozRepl for Perl and for PHP too.


here some snippets for php

The following code sends 3 commands to the MozRepl server and prints the responses.


again: what is aimed:

well i want to fetch a number of pages - as thumbnails
i have a number of pages - stored in a txt-file

example:

PHP Code:
 www.google.com 
www
.altavista.com
www
.yahoo.com
www
.msm.com
www
.oracle.com 


and so on....

See the socketHelper class that does the dirt work


PHP Code:
<?php
 
require_once('socketHelper.php');
 
/* Commands to send to  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) as $command){
    if(
$command=='')continue; //Skip blank lines
    
echo $firefox_socket->send_command($command);
}
 
?>



the Code for socketHelper class


PHP Code:
<?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 a command to MozRepl */
    
public function send_command($command){
        
$command.="\n";
        
socket_write($this->socket,$command);
        return 
$this->read();
    }
 
 
    
/* 
        Read from the Socket until we get a "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 from 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;
    }
}
?>


any hint for the idea to gather the thumbmails?

Reply With Quote
  #2  
Old December 9th, 2012, 02:25 PM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,130 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 23 h 46 m 38 sec
Reputation Power: 1736
If you post others code, please add proper credit to the owner of the source (http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/)
Comments on this post
ptr2void agrees: metabo, copying and pasting code? Say it ain't so!

Reply With Quote
  #3  
Old December 9th, 2012, 05:07 PM
metabo metabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 229 metabo Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 14 h 19 m 9 sec
Reputation Power: 0
hello dear MrFujin

many thanks for the hints

Quote:
Originally Posted by MrFujin
If you post others code, please add proper credit to the owner of the source (http://www.codksediesel.com/tools/peeking-inside-firefox-using-mozrepl/)


thx - thats true

and for the rest of the question - i think i got the solution.
welll - and now i want to set up the mozrepl propperly...


ptr2void -close but no ciguar - but guessing that
you did nt get it

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Running Mozrepl with PHP .... some last questions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap