src/IronWorker.php
private function workerHeader($worker_file_name, $envs = array())
    {
        $export_env = "";
        foreach ($envs as $env => $value) {
            $export_env .= "putenv(\"$env=$value\");\r\n";
        }
        $header = <<<EOL
<?php
/*IRON_WORKER_HEADER*/
$export_env
function getArgs(\$assoc = true)
{
    global \$argv;

    \$args = array('task_id' => null, 'dir' => null, 'payload' => array(), 'config' => null);

    foreach (\$argv as \$k => \$v)
    {
        if (empty(\$argv[\$k + 1]))
        {
            continue;
        }

        if (\$v == '-id') \$args['task_id'] = \$argv[\$k + 1];
        if (\$v == '-d') \$args['dir'] = \$argv[\$k + 1];
        if (\$v == '-payload') \$args['payload_file'] = \$argv[\$k + 1];
        if (\$v == '-config') \$args['config_file'] = \$argv[\$k + 1];
    }

    if (getenv('TASK_ID')) \$args['task_id'] = getenv('TASK_ID');
    if (getenv('TASK_DIR')) \$args['dir'] = getenv('TASK_DIR');
    if (getenv('PAYLOAD_FILE')) \$args['payload_file'] = getenv('PAYLOAD_FILE');
    if (getenv('CONFIG_FILE')) \$args['config_file'] = getenv('CONFIG_FILE');

    if (array_key_exists('payload_file',\$args) && file_exists(\$args['payload_file']))
    {
        \$args['payload'] = file_get_contents(\$args['payload_file']);

        \$parsed_payload = json_decode(\$args['payload'], \$assoc);

        if (\$parsed_payload != null)
        {
            \$args['payload'] = \$parsed_payload;
        }
    }

    if (array_key_exists('config_file',\$args) && file_exists(\$args['config_file']))
    {
        \$args['config'] = file_get_contents(\$args['config_file']);

        \$parsed_config = json_decode(\$args['config'], \$assoc);

        if (\$parsed_config != null)
        {
            \$args['config'] = \$parsed_config;
        }
    }

    return \$args;
}

function getPayload(\$assoc = false)
{
    \$args = getArgs(\$assoc);

    return \$args['payload'];
}

function getConfig(\$assoc = true)
{
    \$args = getArgs(\$assoc);

    return \$args['config'];
}

require dirname(__FILE__)."/[SCRIPT]";
EOL;
        $header = str_replace(
            array('[PROJECT_ID]', '[URL]', '[HEADERS]', '[SCRIPT]'),
            array($this->project_id, $this->url, var_export($this->compiledHeaders(), true), $worker_file_name),
            $header
        );
        return trim($header, " \n\r");
    }
private function workerHeader($worker_file_name, $envs = array())
    {
        $export_env = "";
        foreach ($envs as $env => $value) {
            $export_env .= "putenv(\"$env=$value\");\r\n";
        }
        $header = <<<EOL
<?php
/*IRON_WORKER_HEADER*/
$export_env
function getArgs(\$assoc = true)
{
    global \$argv;

    \$args = array('task_id' => null, 'dir' => null, 'payload' => array(), 'config' => null);

    foreach (\$argv as \$k => \$v)
    {
        if (empty(\$argv[\$k + 1]))
        {
            continue;
        }

        if (\$v == '-id') \$args['task_id'] = \$argv[\$k + 1];
        if (\$v == '-d') \$args['dir'] = \$argv[\$k + 1];
        if (\$v == '-payload') \$args['payload_file'] = \$argv[\$k + 1];
        if (\$v == '-config') \$args['config_file'] = \$argv[\$k + 1];
    }

    if (getenv('TASK_ID')) \$args['task_id'] = getenv('TASK_ID');
    if (getenv('TASK_DIR')) \$args['dir'] = getenv('TASK_DIR');
    if (getenv('PAYLOAD_FILE')) \$args['payload_file'] = getenv('PAYLOAD_FILE');
    if (getenv('CONFIG_FILE')) \$args['config_file'] = getenv('CONFIG_FILE');

    if (array_key_exists('payload_file',\$args) && file_exists(\$args['payload_file']))
    {
        \$args['payload'] = file_get_contents(\$args['payload_file']);

        \$parsed_payload = json_decode(\$args['payload'], \$assoc);

        if (\$parsed_payload != null)
        {
            \$args['payload'] = \$parsed_payload;
        }
    }

    if (array_key_exists('config_file',\$args) && file_exists(\$args['config_file']))
    {
        \$args['config'] = file_get_contents(\$args['config_file']);

        \$parsed_config = json_decode(\$args['config'], \$assoc);

        if (\$parsed_config != null)
        {
            \$args['config'] = \$parsed_config;
        }
    }

    return \$args;
}

function getPayload(\$assoc = false)
{
    \$args = getArgs(\$assoc);

    return \$args['payload'];
}

function getConfig(\$assoc = true)
{
    \$args = getArgs(\$assoc);

    return \$args['config'];
}

require dirname(__FILE__)."/[SCRIPT]";
EOL;
        $header = str_replace(
            array('[PROJECT_ID]', '[URL]', '[HEADERS]', '[SCRIPT]'),
            array($this->project_id, $this->url, var_export($this->compiledHeaders(), true), $worker_file_name),
            $header
        );
        return trim($header, " \n\r");
    }
private function workerHeader ( $ worker_file_name , $ envs = array ( ) ) { $ export_env = "" ; foreach ( $ envs as $ env => $ value ) { $ export_env .= "putenv(\"$env=$value\");\r\n" ; } $ header =  <<<EOL
<?php
/*IRON_WORKER_HEADER*/
$export_env
function getArgs(\$assoc = true)
{
    global \$argv;

    \$args = array('task_id' => null, 'dir' => null, 'payload' => array(), 'config' => null);

    foreach (\$argv as \$k => \$v)
    {
        if (empty(\$argv[\$k + 1]))
        {
            continue;
        }

        if (\$v == '-id') \$args['task_id'] = \$argv[\$k + 1];
        if (\$v == '-d') \$args['dir'] = \$argv[\$k + 1];
        if (\$v == '-payload') \$args['payload_file'] = \$argv[\$k + 1];
        if (\$v == '-config') \$args['config_file'] = \$argv[\$k + 1];
    }

    if (getenv('TASK_ID')) \$args['task_id'] = getenv('TASK_ID');
    if (getenv('TASK_DIR')) \$args['dir'] = getenv('TASK_DIR');
    if (getenv('PAYLOAD_FILE')) \$args['payload_file'] = getenv('PAYLOAD_FILE');
    if (getenv('CONFIG_FILE')) \$args['config_file'] = getenv('CONFIG_FILE');

    if (array_key_exists('payload_file',\$args) && file_exists(\$args['payload_file']))
    {
        \$args['payload'] = file_get_contents(\$args['payload_file']);

        \$parsed_payload = json_decode(\$args['payload'], \$assoc);

        if (\$parsed_payload != null)
        {
            \$args['payload'] = \$parsed_payload;
        }
    }

    if (array_key_exists('config_file',\$args) && file_exists(\$args['config_file']))
    {
        \$args['config'] = file_get_contents(\$args['config_file']);

        \$parsed_config = json_decode(\$args['config'], \$assoc);

        if (\$parsed_config != null)
        {
            \$args['config'] = \$parsed_config;
        }
    }

    return \$args;
}

function getPayload(\$assoc = false)
{
    \$args = getArgs(\$assoc);

    return \$args['payload'];
}

function getConfig(\$assoc = true)
{
    \$args = getArgs(\$assoc);

    return \$args['config'];
}

require dirname(__FILE__)."/[SCRIPT]";
EOL ; $ header = str_replace ( array ( '[PROJECT_ID]' , '[URL]' , '[HEADERS]' , '[SCRIPT]' ) , array ( $ this -> project_id , $ this -> url , var_export ( $ this -> compiledHeaders ( ) , true ) , $ worker_file_name ) , $ header ) ; return trim ( $ header , " \n\r" ) ; }
Contain php code that adds to worker before upload

@param string $worker_file_name
@param array $envs
@return string
Contain php code that adds to worker before upload