1

I am learning how to run iMacros from my php scripts so that PHP script calls an iMacros browser session and passes any variables that I have (url and macro name for example). The iMacros session then runs the iMacro, after the macro is done running it passes the resulting html page back to the PHP script and closes itself. In an ideal world, anyway.

Here is the iMacros calling script:

<?php

require 'src/iimfx.class.php';

$iim = new imacros();

$vars = array();

$iim->play($vars,'grab_data.iim');


?>

But when i run this script from cmd.exe [command line] on WAMP, I get this:

New imacros session started!
Using Proxy: MY_PROXY_IP:MY_PROXY_PORT
-runner -fx -fxProfile default
--------------------------------------------------------
Setting Value IP => MY_PROXY_IP
Setting Value port => MY_PROXY_PORT
Playing Macro proxy.iim
--------MACRO ERROR!-------------------
 ERROR: Browser was not started. iimInit() failed?
--------------------------------------------------------
Playing Macro grab_google.iim
--------MACRO ERROR!-------------------
 ERROR: Browser was not started. iimInit() failed?

P.S. MY_PROXY_IP and MY_PROXY_PORT are replaced with actual numbers both in error messages above and iimfx.class.php.

And here is code for the iimfx.class.php :

<?php

class imacros {
    function __construct($proxyip = 'MY_PROXY_IP', $proxyport = 'MY_PROXY_PORT', $silent = false, $noexit = false) {

        echo "--------------------------------------\nNew imacros session started!\nUsing Proxy: $proxyip:$proxyport\n";
        $this->proxyip = $proxyip;
        $this->proxyport = $proxyport;

        if (empty ( $this->proxyip ))
            echo "NO PROXY!!\n";

        $this->noexit = $noexit;
        $this->fso = new COM ( 'Scripting.FileSystemObject' );
        $this->fso = NULL;

        $this->iim = new COM ( "imacros" );

        $toexec = "-runner -fx -fxProfile default";

        if ($silent === true)
            $toexec .= " -silent";

        if ($noexit === true)
            $toexec .= " -noexit";

        echo $toexec . "\n";

        $this->iim->iimInit ( $toexec );

        if (! empty ( $this->proxyip )) {
            $dvars ['IP'] = $this->proxyip;
            $dvars ['port'] = $this->proxyport;
            $this->play ( $dvars, 'proxy.iim' );
        }
    }

    function __destruct() {
        if ($this->noexit === false)
            $this->iim->iimExit ();
    }

    function play($immvars = '', $macro) {

        echo "--------------------------------------------------------\n";

        if (is_array ( $immvars )) {
            foreach ( $immvars as $key => $value ) {
                echo "Setting Value $key => $value\n";
                $this->iim->iimSet ( "-var_" . $key, $value );
            }
        }

        echo "Playing Macro $macro\n";
        $s = $this->iim->iimPlay ( $macro );

        if($s>0){
            echo "Macro successfully played!\n";
        }else{
            echo "--------MACRO ERROR!-------------------\n ERROR: " . $this->getLastError() . "\n";
        }
        return $s;
    }

    // This function retrieves extracts in your iMacros script if you have any. 
    function getLastExtract($num) {
        return $this->iim->iimGetLastExtract ( $num );
    }

    // Returns the last error :)
    function getLastError(){
        return $this->iim->iimGetLastError();
    }

    // Enables/disables images
    function setImages($images = 1) { // 1 = on 2 = off

        $dvars ['images'] = $images;
        $this->play ( $dvars, 'images.iim' );

    }

    // Enables or disables adblockplus
    function enableABP($status = true){

        $dvars['status'] = $status;
        $this->play ( $dvars, 'abp.iim' );

    }

}

?>

Is there something I am missing here? I have iimRunner.exe running during all of this [started manually before running the script] and I have iMacros Browser V8+. Also, my grab_data.iim and all other required .iim are in the same place as the php script that is trying to call them and execute them.

Any kind of help and/or steer towards the right direction would be greatly appreciated!! Thanks in advance.

codepreneur
  • 466
  • 6
  • 19
  • 1
    I find question very interesting and I do iMacros but not in PHP. Thumbs up for this question so that others can see it. – edinvnode Feb 26 '13 at 20:53

1 Answers1

-1

U must by start the immrunner, before start the script =)

http://wiki.imacros.net/iimRunner