note 97160 modified in book.curl by danbrown
| From: | danbrown@php.net | Date: | Mon, 05 Apr 2010 22:23:27 +0000 |
| Subject: | note 97160 modified in book.curl by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167714@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.
--was--
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.
http://php.net/manual/en/book.curl.php