SORU
26 EYLÜL 2008, Cuma


bağlantı erken kapatın

Oldukça uzun bir süreci başlatacak bir AJAX arama (JQuery ile) girişimde bulundum. Senaryoyu sadece bir tepki sürecinin başladığını bildiren göndermek istiyorum, ama JQuery PHP komut dosyası çalıştıran bitene kadar yanıt verilmiş olmaz.

Bir "çıktı; ne iş gibi görünüyor. tampon" Başlığı (aşağıda), ve yakın zamanda bu denedim Bir fikriniz var mı? ya bu JQuery yapmam gereken bir şey mi?

<?php

echo( "We'll email you as soon as this is done." );

header( "Connection: Close" );

// do some stuff that will take a while

mail( 'dude@thatplace.com', "okay I'm done", 'Yup, all done.' );

?>

CEVAP
20 Kasım 2009, Cuma


Gerekli bu 2 başlıkları göndermek için:

Connection: close
Content-Length: n (n = size of output in bytes )

Çıkış boyutunu bilmek gerekir beri, çıkış tampon, tarayıcı sifonu Çek o zaman gerekir:

// buffer all upcoming output
ob_start();
echo "We'll email you as soon as this is done.";

// get the size of the output
$size = ob_get_length();

// send headers to tell the browser to close the connection
header("Content-Length: $size");
header('Connection: close');

// flush all output
ob_end_flush();
ob_flush();
flush();

// if you're using sessions, this prevents subsequent requests
// from hanging while the background process executes
if (session_id()) session_write_close();

/******** background process starts here ********/

Eğer web sunucusu otomatik gzip kullanıyorsa da, çıkış sıkıştırma (örn. Apache mod_deflate ile), bu çıkış gerçek boyutu değişti çünkü işe yaramaz, İçerik-Uzunluk artık doğru değil. Gzip devre dışı bırakmak, belirli komut dosyası sıkıştırma.

Daha fazla ayrıntı için http://www.zulius.com/how-to/close-browser-connection-continue-execution ziyaret edin

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Joseph Herscher

    Joseph Hersc

    14 Mart 2007
  • LatinNinja99

    LatinNinja99

    28 EKİM 2011
  • Tech4Geeks

    Tech4Geeks

    8 Ocak 2012