Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is PHP or PHP based web framework stateful or stateless? [closed]

Along the same lines that for java centric applications, Play framework is stateless and lift framework is stateful as is any servlet or Java EE container like Tomcat or GlassFish is statefull, is PHP web framework like zend or cake php stateless or stateful and why?

like image 811
ace Avatar asked Jun 13 '11 06:06

ace


People also ask

Is PHP stateless or stateful?

PHP is stateless. You don't get to keep connections across requests.

What is stateless in PHP?

Stateless Protocols are the type of network protocols in which Client send request to the server and server response back according to current state. It does not require the server to retain session information or a status about each communicating partner for multiple request.

Is HTTP stateful or stateless?

The HTTP protocol is a stateless one. This means that every HTTP request the server receives is independent and does not relate to requests that came prior to it.

Is REST API stateful or stateless?

Is REST API stateless or stateful? A. REST APIs are stateless because, rather than relying on the server remembering previous requests, REST applications require each request to contain all of the information necessary for the server to understand it.


2 Answers

PHP by itself has no state. Each request is completely unique. It's very close to the bare metal of HTTP in this regard.

To implement state on top of that you can use sessions, databases, shared memory, files or anything else that somehow retains state. Frameworks like Zend or Cake offer abstractions for these mechanisms that make it appear stateful out of the box to varying degrees. PHP is never truly keeping state though.

like image 130
deceze Avatar answered Sep 21 '22 15:09

deceze


It is not all about Java or PHP. HTTP is a stateless protocol.

To make it stateful, the developer (programmer) has to make sure that all relevant information is stored and make sure that all relevant information is read back in when the script is called upon.

Most of the servers provide session management for stat management.

As to why stateless - stateful session add significant memory and performance overhead see:

models-with-persistent-state-between-http-requests

like image 44
Arpan Khandelwal Avatar answered Sep 18 '22 15:09

Arpan Khandelwal