Php Mantık Sorusu
-
Hocalarım Şimdi benim bir sayfam var 3 e böldüm bunu. Menü Header ve mainpage diye. mainpage orta kısım. ve sayfa değişiklikleri burda oluyor. Şimdi.. Header de bildirim kısmı logo vs vs var bu header kısmı tüm sayfalarda include edilmiş şekilde çağrılıyor sayfa yüklendiğinde. Header kısmındaki bildirim'i Ajax ile yaptım. Socket vs. yok . her 0.2 sn de bir VT de bildirim varmı sorgulatıyorum. Varsa göstertiyorum gibi.. Buraya kadar herhangi bir sıkıntı yok. Fakat ben bir sayfayı yeni açtığım anda yani AnaSayfadan menüler kısmındaki herhangi bir sayfaya tıkladığımda bana bildirimleri tekrar getirdiği için Bildirim sesi çalıyor. Header include edildiği için. Bunu ben nasıl çözebilirim ? Sayfa yüklendiği anda çalmasını istemiyorum. sadece bildirim geldiği anda gelsin istiyorum.. ama nasıl olcak ? :/ Bildirim sesi bildirim gelmesede sayfa değişikliklerinde çalıyor. menü kısmındaki bildirimler yüklenirken..
-
Hocam öncelikle yapı cok sakat gibi duruyor, başlarda sıkıntı cıkartmayabilir ancak kullanıcı sayısı arttıkca başını ağrıtacaktır.
sorununa gelecek olursak cookie veya session ile yapabilirsin diye düşünüyorum.
veritabanından sorgu yaptıgın an yeni bildirim varsa onu alırsın, sonbildirim diye bir cookie oluşturursun ve gelen bildirimin id veya herhangi bir uniq değerini bu cookiye atarsın.
sayfa değiştiği an tekrar ajax sorgulaması yapıldığı için aynı bildirim tekrar gelicek, ancak sen sonbildirim cookiesindeki id ile ajax sorgusundan gelen bildirimin idlerini karşılaştırırsın, tutuyorsa sesi çaldırmazsın
-
Yapı neden sakat ? Cokkie mantığı güzelmiş. Teşekkürler onu deneyeceğim de bir şüphe oluştu içimde bunu demenle . Ne gibi sıkıntılar çıkarır bana ilerde ? ve hatam nedir ?
-
yüksek trafikli sitelerde sorgu çok olacağından mysql e yük bineceği için sakat demiş hocam.
0.2 saniye makineli gini ateş eder 3-5 saniye yapsan daha rahatlar
bendede benzer bir sistem var önce kullanıcılar arası mesajlaşma olarak yapılmıştı ama sonradan anlık chate dönüştü ben yineden 5 saniyede bir ajax la check ediyorum
ses olayına gelirce eğer üyelik sistemine dahilse o kullanının mesajı görüp görmediğini db de tutman doğru olur
yok public bir sistem ise Genki hocanın dediği gibi session yada cookie ile kontrol etmen lazım
-
Bu programı maksimum 500 kişi kullanacak. Toplam kullanıcı sayısı bu . Mysql gene zorlanır mı ? ben pek sıkıntı olmaz diye düşündüm ama azaltabilirim 1 sn veya 2 saniyeye. Bildirim 2 sn geç gelse birşey olmaz sanırım.
-
Sorunun cevabı comet. Forever frame ya da long polling tekniklerini araştır. setInterval'le cekersin ama 0.2 sn falan çok kısa zaman aralığı. Herhangi bir problemden dolayı server o zaman aralığında cevap vermezse ne yapacaksın?
-
WebSocket mantığı sanırım bu söyledikleriniz , comet haricinde. Port dinleme olayları. eğer sunucuda veri eklendi ise şutla mesaja ? Doğru anladı isem. Bunların farkı nedir merak ediyorum bazıları Ajax kullanıp veri tabanından (DOĞRU POST) ile yani her seferinde verileri çekmek yerine. 1 sorgu ile veya bi algoritma ile yeni veri geldi mi ? Sorusunun cevabı ile ajax'ın cevap vermesi olayının daha verimli olduğunu söylüyor . Benim yanlışım her türlü veriyi getirtip okuyorum. Yani benim asıl yapmam gereken anladığım kadarı ile.
Şuan chat sayfasında bulunan Mesaj miktarı. Örneğin 10 olsun.
Ajax'a 10 u göndereceğim
Ajax'daki sonsuz bir döngü ile 10 dan büyük bir mesaj olduğu anda hemen cevap verdirme işlemini yapacağım.
Ajax cevap verince yeni gelen mesajı'ı div'e basacağım. Yani bunu anladım ben aksi halde Port dinleyerek bir socket yazmam gerekiyor.
-
Hocam bence nodejs kullanmaya bak. illede böyle kullanacaksan zaman aralığını 15 20 saniyelere kadar çek.
Ayrıca ben 2 3 yıl öncesine kadar bi facebook uygulaması yazmıstım. dediğin şekilde bende ajax yenileme kullanmıştım 1 saniyeler felan bayağı bi problem olmuştu. 20 saniye için 200 300 kullanıcı sorun olmamıştı. ama 500 kullanıcı için bilmem. genede zamanı hiç yoksa 10 15 saniyeye çıkar öle bi gözlem yap. bildirimin 10 sn geçmesi sorun olmaz. Yinede yoğun işlemlerlede serverdan cevap dönmeyebilir.
-
-
Çok eski bir metot o.
Longpolling terimi incele.
Daha da güzel bir yapı için : http://elephant.io/ ' ya bakabilirsin.
Daha daha da güzeli, nodejs ile entegrasyon kur.
Bir diğer opsiyon da Trigger yazabilirsin mysql' e. (Tavsiye etmem)
Eğer mobil için service yazıyorsan, GCM ile broadcast yaparak client' dan istek attırabilirsin.
Ek - 1 : Eğer illa böyle yapıcam diyorsan; flags adında bir tablo oluştur. Real time değişiklikler için 0-1 ile burada yap. Ve 0.2 saniye de poll ederken sadece bu tabloyu kontrol ettir.
Ek - 2 : Node.js PHP entegrasyonu ile ilgili makale : https://entwickler.de/webandphp/integrating-node-js-with-php-125830.html
Ek - 3 : Node.js PHP entegrasyonu ile ilgili fikir vermesi için video : https://www.youtube.com/watch?v=xIKRwRU9UTs
Ek - 4 : Node.js PHP entegrasyonu Git uygulaması fikir vermesi için : https://github.com/isaacsu/twich
Ek - 5 : Longpolling hakkında örnek uygulama ve makale : https://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery
Ek - 6 : Android ve PHP için örnek real time Chat Uygulaması (GCM ile Broadcast) : http://www.androidhive.info/2016/02/android-push-notifications-using-gcm-php-mysql-realtime-chat-app-part-1/
Araştırman gereken keyword' ler : HTML5 Web Sockets, Node.js Socket.IO, Longpolling.
-----------------------
In the examples below the client is the browser and the server is the webserver hosting the website.
Before you can understand these technologies, you have to understand classic HTTP web traffic first.
Regular HTTP:
- A client requests a webpage from a server.
- The server calculates the response
- The server sends the response to the client.
Ajax Polling:
- A client requests a webpage from a server using regular HTTP (see HTTP above).
- The requested webpage executes JavaScript which requests a file from the server at regular intervals (e.g. 0.5 seconds).
- The server calculates each response and sends it back, just like normal HTTP traffic.
Ajax Long-Polling:
- A client requests a webpage from a server using regular HTTP (see HTTP above).
- The requested webpage executes JavaScript which requests a file from the server.
- The server does not immediately respond with the requested information but waits until there's
new information available. - When there's new information available, the server responds with the new information.
- The client receives the new information and immediately sends another request to the server, re-starting the process.
HTML5 Server Sent Events (SSE) / EventSource:
- A client requests a webpage from a server using regular HTTP (see HTTP above).
- The requested webpage executes javascript which opens a connection to the server.
-
The server sends an event to the client when there's new information available.
- Real-time traffic from server to client, mostly that's what you'll need
- You'll want to use a server that has an event loop
- Not possible to connect with a server from another domain
- If you want to read more, I found these very useful: (article), (article), (article), (tutorial).
HTML5 Websockets:
- A client requests a webpage from a server using regular http (see HTTP above).
- The requested webpage executes JavaScript which opens a connection with the server.
-
The server and the client can now send each other messages when new data (on either side) is available.
- Real-time traffic from the server to the client
and from the client to the server - You'll want to use a server that has an event loop
- With WebSockets it is possible to connect with a server from another domain.
- It is also possible to use a third party hosted websocket server, for example Pusher orothers. This way you'll only have to implement the client side, which is very easy!
- If you want to read more, I found these very useful: (article), (article) (tutorial).
- Real-time traffic from the server to the client
Comet:
Comet is a collection of techniques prior to HTML5 which use streaming and long-polling to achieve real time applications. Read more on wikipedia or this article.
Now, which one of them should I use for a realtime app (that I need to code). I have been hearing a lot about websockets (with socket.io [a node.js library]) but why not PHP ?
You can use PHP with WebSockets, check out "http://socketo.me/"
Stackoverflow' dan alıntıdır.
HTML5 Web Sockets Browser Desteği : http://caniuse.com/#search=websockets
ozgunlu tarafından 15/Tem/16 13:10 tarihinde düzenlenmiştir -
@ozgunlu videoları da izleyeyim abi teşekkürler. Android tarafında bir işim yok Android'i şuan sadece freelance için kullanıyorum Php Jquery Botstrap ajax vs. yeni öğreniyorum. Makale için de tekrar teşekkürler :)