Frage

Ich möchte eine Webanwendung mit einem Modell erstellen, das zwischen HTTP-Anforderungen bestehen bleibt.Aus dem, was ich Sprachen wie PHP verstehe, behandeln jede HTTP-Anfrage als brandneue Verbindung mit Ausnahme einiger globaler Variablen wie Session;Jedes Mal, wenn der Benutzer Seiten ändert, werden alle meine PHP-Klassen erneut in den Speicher geladen (und jede AJAX-Anforderung tut dies auch) - erfordern Sie jedes Mal aus der Datenbank.

Bin ich falsch oder versuche ich, einen Kreis in einem Platz passen?Memcached scheint eine gute Lösung zu sein, um mein Modell zwischen den Seitenanfragen im Speicher zu halten, muss jedoch noch den Cache laden.PHP CLI schien vielversprechend zu sein, aber nachdem er mehr anschauerte, schien es mehr, als wäre es mehr Ärger, als es wert war.Irgendwelche Vorschläge?

War es hilfreich?

Lösung

You should avoid requiring a persistent state in your web application; HTTP is stateless and you need to design your business logic around that. Also, PHP isn't very memory-leak safe since it isn't meant to act as a daemon or run for extended periods. You shouldn't be maintaining a database of information in PHP variables either. You can cache expensive query results in memcache and retrieve them with very little latency.

You can serialize your model, store it in a session (or memcache), and deserialize it on the next request in order to keep relevant variables within scope between requests. If you share a bit more about the specifics of your application, perhaps we can help you figure out the best way to handle this.

Andere Tipps

I do agree that one should try to avoid sharing states between requests. But in rare cases, such as to implement a simple message queue over HTTP, It's desirable to have this feature in hand.

For php, one could use IPC via the php_shmop extension.

For nodejs, I found this

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top