chadhutchins/codeigniter-mcurl — Issue #1: Unable to add new calls after the execution of previous calls
Author: sebdesign
Created: 2011-11-20 04:03:34+00:00
State: open

```php
$this->load->library('mcurl');
$this->mcurl->add_call("get","http://foo.com");
$this->mcurl->add_call("get","http://bar.com");
$responses = $this->mcurl->execute();

$this->mcurl->add_call("get","http://baz.com");
// PHP Warning: curl_multi_add_handle(): 42 is not a valid cURL handle resource in qux.php on line 42
```

I'm adding a few calls which are executing fine, without bugs.
Later on I add some other calls and I receive a warning: *curl_multi_add_handle(): 42 is not a valid cURL Multi Handle resource.*

This is caused because after the execution the curl multi handle is being closed. Therefore `$this->curl_parent` becomes a resource of type *Unknown*. When `$this->curl_parent` is reused in the curl functions it generates this warning and doesn't work.

In `$this->add_call()` you should check if `$this->curl_parent` is not closed, and if it is, you should initialize it again.
Here's a snippet I added just before the `curl_multi_add_handle()` at the end of the method:

```php
if(get_resource_type($this->curl_parent) == 'Unknown')
{
$this->curl_parent = curl_multi_init();
}
```

I know that the purpose of multi curl is to add all the calls before executing them, but I need to call and execute cURLs in different parts during the runtime, which I can't merge together. Also CI libraries should be reusable at any moment, and I think it would be handful to use it at any moment.