note 97160 added to book.curl
| From: | cliffclofattygmaildottycom at osu1 dot php dot net | Date: | Mon, 05 Apr 2010 21:21:04 +0000 |
| Subject: | note 97160 added to book.curl | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167713@lists.php.net to get a copy of this message | ||
A solution that addresses repeat calls to the same set of urls using the same connection simulating
frequent ajax calls in separate browser tabs.
In a unique situation you may need to set a cookie then use that cookie for multiple separate
persistent connections using the same session cookie. The problem is the session cookie may change
while your doing your persistent calls. If you set every curl handle to update a shared cookiejar
on close you may overwrite the new found session value with the old session value depending on the
closing order of your handles. Also, because the cookiejar is only written to on a curl_close, you
may be using dissimilar or old session info in some of your 'faked browser tabs'.
To solve this problem I created a unique handle that opens and closes specifically to set a cookie
file using CURLOPT_COOKIEJAR. Then I just use the read-only CURLOPT_COOKIEFILE on the multiple
separate persistent handles.
This solves the problem of shared cookies fighting to write their values and keep persistent calls
using the most up to date cookie information.
Note: In my case the multiple calls were in a while loop and I was using php in shell. The session
cookie value plus browser type limited the number of connections available and i wanted to use the
max connections per session.
Please let me know if there is a better way.
----
Server IP: 69.147.83.197
Probable Submitter: 69.230.84.228
----
Manual Page -- http://www.php.net/manual/en/book.curl.php
Edit -- https://master.php.net/note/edit/97160
Del: integrated -- https://master.php.net/note/delete/97160/integrated
Del: useless -- https://master.php.net/note/delete/97160/useless
Del: bad code -- https://master.php.net/note/delete/97160/bad+code
Del: spam -- https://master.php.net/note/delete/97160/spam
Del: non-english -- https://master.php.net/note/delete/97160/non-english
Del: in docs -- https://master.php.net/note/delete/97160/in+docs
Del: other reasons-- https://master.php.net/note/delete/97160
Reject -- https://master.php.net/note/reject/97160
Search -- https://master.php.net/manage/user-notes.php