Pommo_Mail_Ctl::spawn PHP Method

spawn() public method

* spawn spawns a page in the background, used by mail processor.
public spawn ( $page, $log = false )
$log
    function spawn($page, $log = false)
    {
        $logger = Pommo::$_logger;
        /* Convert illegal characters in url */
        $page = str_replace(' ', '%20', $page);
        $errno = '';
        $errstr = '';
        // NOTE: fsockopen() SSL Support requires PHP 4.3+ with OpenSSL compiled in
        $ssl = Pommo::$_ssl ? 'ssl://' : '';
        $out = "GET {$page} HTTP/1.1\r\n";
        $out .= "Host: " . Pommo::$_hostname . "\r\n";
        //$out .= 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204\r\n';
        //$out .= "Keep-Alive: 300\r\n";
        //$out .= "Connection: keep-alive\r\n";
        //$out .= "Referer: Pommo::$_http\r\n";
        // to allow for basic .htaccess http authentication,
        //   uncomment and fill in the following;
        // $out .= "Authorization: Basic " . base64_encode('username:password')."\r\n";
        $out .= "Connection: Close\r\n\r\n";
        $spawnPage = $out;
        $logger->addMsg('Attempting to spawn ' . ($ssl ? 'https://' : 'http://') . Pommo::$_hostname . ':' . Pommo::$_hostport . $page, 2, TRUE);
        $socket = fsockopen($ssl . Pommo::$_hostname, Pommo::$_hostport, $errno, $errstr, 25);
        // LOG SPAWN ATTEMPTS TO FILE *TEMP, DEBUG*
        if ($log || Pommo::$_debug) {
            if (is_file(Pommo::$_workDir . '/SPAWN_0')) {
                copy(Pommo::$_workDir . '/SPAWN_0', Pommo::$_workDir . '/SPAWN_1');
            }
            if ($handle = fopen(Pommo::$_workDir . '/SPAWN_0', 'w')) {
                fwrite($handle, $out);
                fclose($handle);
            }
        }
        if ($socket) {
            fwrite($socket, $out);
            sleep(1);
            fclose($socket);
            // spawned script must have ignore_user_abort, eh? ;)
        } else {
            $msg = time() . ' >>> Error Spawning Page! ** Errno : Errstr: ' . $errno . ' : ' . $errstr;
            $logger->addMsg($msg, 3, TRUE);
            trigger_error($msg);
            return false;
        }
        return true;
    }

Usage Example

Example #1
0
 * the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with program; see the file docs/LICENSE. If not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
/**********************************
	INITIALIZATION METHODS
 *********************************/
define('_poMMo_support', TRUE);
require 'bootstrap.php';
Pommo::init();
require_once Pommo::$_baseDir . 'classes/Pommo_Mail_Ctl.php';
set_time_limit(0);
$code = Pommo_Helper::makeCode();
if (!Pommo_Mail_Ctl::spawn(Pommo::$_baseUrl . 'mailing.runtime2.php?code=' . $code)) {
    Pommo::kill('Initial Spawn Failed! You must correct this before poMMo can send mailings.');
}
echo 'Initial Run Time: ' . ini_get('max_execution_time') . ' seconds <br>';
echo '<br/> This test takes at least 90 seconds. Upon completetion "SUCCESS" will be printed. If you do not see "SUCCESS", the max runtime should be set near the second highest "reported working" value.';
echo '<hr>';
echo '<b>Reported working value(s)</b><br />';
ob_flush();
flush();
sleep(5);
if (!is_file(Pommo::$_workDir . '/mailing.test.php')) {
    // make sure we can write to the file
    if (!($handle = fopen(Pommo::$_workDir . '/mailing.test.php', 'w'))) {
        Pommo::kill('Unable to write to test file!');
    }
    fclose($handle);
All Usage Examples Of Pommo_Mail_Ctl::spawn