0

见鬼,我有一个 jabber 脚本,它会自动为我将所有 msgs 加载到 mysql 数据库中......但是,在它完成之后,脚本仍然保持/粘住......我怎么能在一次运行后退出?请帮助,我能得到任何帮助,我将非常感谢!

<?php

// activate full error reporting
//error_reporting(E_ALL & E_STRICT);

include 'XMPPHP/XMPP.php';


$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp', 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);


// $conn->autoSubscribe();

$vcard_request = array();

try {
    $conn->connect();
    while(!$conn->isDisconnected()) {
        $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));
        foreach($payloads as $event) {
            $pl = $event[1];
            switch($event[0]) {
                case 'message': 
                    print "---------------------------------------------------------------------------------\n";
                    print "Message from: {$pl['from']}\n";
                    if($pl['subject']) print "Subject: {$pl['subject']}\n";
                    print $pl['body'] . "\n";
                    print "---------------------------------------------------------------------------------\n";
                    // $conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);

                    $cmd = explode(' ', $pl['body']);
                    if($cmd[0] == 'quit') $conn->disconnect();
                    if($cmd[0] == 'break') $conn->send("</end>");
                    if($cmd[0] == 'vcard') {
                        if(!($cmd[1])) $cmd[1] = $conn->user . '@' . $conn->server;
                        // take a note which user requested which vcard
                        $vcard_request[$pl['from']] = $cmd[1];
                        // request the vcard
                        $conn->getVCard($cmd[1]);
                    }

                break;
                case 'presence':
                    print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
                break;
                case 'session_start':
                    print "Session Start\n";
                    $conn->getRoster();
                    $conn->presence($status="Cheese!");
                break;
                case 'vcard':
                    // check to see who requested this vcard
                    $deliver = array_keys($vcard_request, $pl['from']);
                    // work through the array to generate a message
                    print_r($pl);
                    $msg = '';
                    foreach($pl as $key => $item) {
                        $msg .= "$key: ";
                        if(is_array($item)) {
                            $msg .= "\n";
                            foreach($item as $subkey => $subitem) {
                                $msg .= "  $subkey: $subitem\n";
                            }
                        } else {
                            $msg .= "$item\n";
                        }
                    }
                    // deliver the vcard msg to everyone that requested that vcard
                    foreach($deliver as $sendjid) {
                        // remove the note on requests as we send out the message
                        unset($vcard_request[$sendjid]);
                        $conn->message($sendjid, $msg, 'chat');
                    }
                break;
            }
        }
    }
} catch(XMPPHP_Exception $e) {
    die($e->getMessage());
}
?>
4

2 回答 2

0

我建议你有两种方法:
1-使用“set_time_limit”函数在指定秒后杀死脚本并引发错误。
2-在while循环之前定义一个变量并节省时间:

$time=time();

在 while 循环的末尾添加以下代码:

if($time+TimeInSeconds<time()) exit();

这两种方式可以在几秒钟后停止脚本。我希望它会有所帮助。

于 2013-08-09T11:02:47.287 回答
0

删除while条件并尝试。我认为它会起作用。

比使用任何标志变量并将其添加到 while 循环中。

于 2013-08-09T11:09:40.787 回答