Asked  7 Months ago    Answers:  5   Viewed   28 times

I'm doing some cURL work in php 5.3.0.

I'm wondering if there is any way to tell the curl handle/object to keep the cookies in memory (assuming I'm reusing the same handle for multiple requests), or to somehow return them and let me pass them back when making a new handle.

Theres this long accepted method for getting them in/out of the request:

curl_setopt($ch, CURLOPT_COOKIEJAR, $filename); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $filename);

But I'm hitting some scenarios where I need to be running multiple copies of a script out of the same directory, and they step on each others cookie files. Yes, I know I could use tempnam() and make sure each run has its own cookie file, but that leads me to my 2nd issue.

There is also the issue of having these cookie files on the disk at all. Disk I/O is slow and a bottle neck I'm sure. I dont want to have to deal with cleaning up the cookie file when the script is finished (if it even exits in a way that lets me clean it up).

Any ideas? Or is this just the way things are?

 Answers

93

You can use the CURLOPT_COOKIEJAR option, and set the file to "/dev/null" for Linux / MacOS X or "NULL" for Windows. This will prevent the cookies from being written to disk, but it will keep them around in memory as long as you reuse the handle and don't call curl_easy_cleanup().

Wednesday, March 31, 2021
 
DilbertDave
answered 7 Months ago
88

You should only call curl_close() when you know you're done with that particular handle, or if switching from its current state to a new one (ie: changing a ton of options via curl_setopt() would be faster by going from a clean new handle than your current "dirty" one.

The cookiejar/file options are only strictly necessary for maintaining cookies between seperate curl handles/invokations. Each one's independent of the others, so the cookie files are the only way to share between them.

Wednesday, March 31, 2021
 
huhushow
answered 7 Months ago
23

You need to add the Curl libraries to the command line PHP.ini.

You can probably just copy the file C:wampbinapacheApache2.2.xbinphp.ini to c:wampbinphpphp5.3.10php.ini (adjust for the actual directories on your system).

Wednesday, March 31, 2021
 
Fanda
answered 7 Months ago
81

mmap a special file, like /dev/zero (or use MAP_ANONYMOUS) as PROT_NONE, later use mprotect to commit.

Tuesday, June 22, 2021
 
pamelus
answered 5 Months ago
95

One, probably not too pretty approach, could be to override the default height values for the ActionBar in dimens.xml.

E.g. the default value in portrait is:

<dimen name="abs__action_bar_default_height">48dip</dimen>

And in landscape:

<dimen name="abs__action_bar_default_height">40dip</dimen>

There might be a cleaner way to do it, but I have to admit I know too little about the internals of ActionBarSherlock for that.


Edit: Come to think of it, this probably won't work when the native ActionBar is being used on ICS, since the height will then resolve to the platform value in ?android:attr/actionBarSize. I'd recommend you wait for a better suggestion, e.g. from Jake himself.

Second edit: After Jake's reply it seems like all you need to do to make it work with ActionBarSherlock on both ICS and pre-ICS devices is add the following to your app's theme:

<item name="actionBarSize">@dimen/some_value</item>
<item name="android:actionBarSize">@dimen/some_value</item> 

You can then add the actual values in the relevant portrait/land resource buckets.

Third edit [thanks alvarolb]: XML Example for the style:

<?xml version="1.0" encoding="utf-8"?>
<resources>   
    <style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarSize">48dip</item>
        <item name="android:actionBarSize">48dip</item> 
    </style> 
</resources>

And in the corresponding activity, set this new style

android:theme="@style/Theme.Styled"

and.. it works!

Monday, September 20, 2021
 
Michael Hampton
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share