문제

HTTP 요청간에 지속되는 모델로 웹 응용 프로그램을 만들고 싶습니다.PHP와 같은 언어를 이해하는 것과 같은 일부 전역 변수를 제외하고 각 HTTP 요청을 브랜드 새 연결로 처리합니다.따라서 사용자가 페이지를 변경할 때마다 내 PHP 클래스가 모두 메모리에로드됩니다 (각 AJAX 요청도) - 데이터베이스에서 빌드해야합니다.

나는 틀리고 있거나 나는 원을 사각형에 맞추려고 노력하고 있습니까?Memcached는 페이지 요청간에 모델을 메모리로 유지하기위한 좋은 해결책이지만 여전히 캐시를로드해야합니다.PHP CLI는 유망한 것처럼 보였지만 그것을 보면서 더 많은 문제가 될 것 같았습니다.어떤 제안?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top