не могут выполнятся параллельно без процессов или тредов
физически никак
! |
Invis1ble |
// Bind event to Before user leaves page with function parameter e
$(window).on('beforeunload', function(e) {
function Messanger() {
this.last = 0;
this.timeout = 360;
this.comet = 0;
var self = this;
// this.putMessage = function(id, data) {
// // callback, добавляет сообщения на страницу, вызывается из полученных с сервера данных
// //self.last = id;
// console.log(data)
// }
this.parseData = function(message) {
// простая обработка данных полученных с сервера, разбиваем строки и выполняет функции
var items = message.split(';');
if (items.length<=1) return false;
for (var i=0;i<items.length;i++) {
items[i];
}
setTimeout(self.connection, 1000);
}
this.connection = function() {
// здесь открывается соединение с сервером
var sParams = '&phpfox[ajax]=true&phpfox[call]=';
for(var sKey in oComet)
{
sParams += sKey + ((self.last != 0) ? '&comet_item=' + self.last : (isset(oComet[sKey]) ? '&' + ltrim(oComet[sKey], '&') : '' ));
if (!sParams.match(/phpfox\[security_token\]/i))
{
sParams += '&phpfox[security_token]=' + oCore['log.security_token'];
}
sParams += '&phpfox[is_admincp]=' + (oCore['core.is_admincp'] ? '1' : '0');
console.log('Connection Establishment:' + sParams);
self.comet = $.ajax({
type: "POST",
asynch: true,
url: getParam('sJsComet'),
data: sParams,
cache: false,
timeout: self.timeout * 1000,
success: self.parseData,
error: function()
{
console.log('Empty data');
setTimeout(self.connection, 1000);
}
});
sParams = '';
}
}
this.init = function() {
//setInterval(self.connection(), self.timeout*1000);
self.connection();
}
this.kill = function()
{
self.connection = false;
}
this.init();
}
public function refreshMessage()
{
//echo 'console.log(\'Mail_Component_Ajax_Ajax\');';
$iCometItem = $this->get('comet_item');
$iCometLimit = 360;
$iCometTime = time();
set_time_limit($iCometLimit + 5);
$oMail = Phpfox::getService('mail');
while ( time() - $iCometTime < $iCometLimit)
{
if($oMail->getNextComet($this->get('comet_item')))
{
$this->template()->assign(array(
'aMail' => $oMail->getMail($oMail->getLastMail())
)
)->getTemplate('mail.block.entry');
echo '$(\'#js_append\').prepend( \' ' . $this->getContent(true) . ' \');';
echo 'msg.last = ' . $oMail->getLastMail() . ';';
flush();
exit;
}
sleep(5);
}
}