PHP concurrent changes on session variable for same user? -
suppose have user variable $_session['variable'] may or may not modified user access page.
suppose same user has several browser windows open , somehow makes simultaneous requests server result on changes session variable.
questions:
how server "queue" these changes, since targeted @ same variable? there potential server error here?
is there way "lock" session variable reading/writing in order implement kind of status check before changing value?
edit ( unheilig cleanup)
regarding "queueing", interested in happens if 2 requests arrive @ same time:
change x 1
change x 2
i know doesn't seem real world scenario, came mind when designing something. become problem if system allows many concurrent requests same user.
each individual php session 'locked' between call session_start() , either call session_write_close() or end of request, whichever sooner.
most of time never notice behaviour.
however, if have site make many concurrent requests* these requests appear queue in first-come-first-served order.
to clear; in typical apache/php setup requests come in server and start php executions concurrently. session_start() call block/pause/wait/queue because it's waiting gain file-lock on session file (or similar depending on session_hander).
to increase request throughput or reduce waiting requests therefore:
- open , close session (session_start(), do_work(), session_write_close()) rapidly possible; reduce time session locked writing.
- make sure you're not leaving session open on requests doing long work (accessing 3rd party apis, generating or manipulating documents, running long database queries etc).. unless absolutely necessary.
- avoid, possible, touching session @ all. restful possible.
- manage queuing , debouncing of requests elegantly possible on client side of application
hope helps.
j.
*ajax & frame/iframe heavy applications exhibit problem.
Comments
Post a Comment