Curl and pcntl_fork()
<p>I have some code that is used to check links on a website and in trying to make it "threaded", the code was updated to use pcntl_fork().</p>

<p>The parent code is working for SSL and non-SSL URL's but the child code is only working for non-SSL URL's. I've noted in the code where it works and where it doesn't.</p>

<p>Here is my fork code. I know the code below will loop forever, I have taken out the loop control code so it is more readable.</p>

<pre><code>$this-&gt;initialize_curl();
$this-&gt;connect_database();

// prime the queue
$this-&gt;add_url_to_queue($this-&gt;source_url, 0, 0);
$this-&gt;process_next_url_in_queue($this-&gt;get_next_url_in_queue());

// SSL and non-SSL work at this point

// loop until we have processed all URL's
while (1) {
  $url = $this-&gt;get_next_url_in_queue();

  // disconnect from the database before forking since we don't want to
  // share the database connection with child processes - the first one
  // will close it and ruin the fun for the other children.
  curl_close($this-&gt;ch);
  $this-&gt;db-&gt;close();

  // create child
  $pid = pcntl_fork();

  // handle forked processing
  switch ($pid) {

    // error
    case -1:
      print "Could not fork\n";
      exit;

    // child
    case 0:

      // seperate database and curl for the child
      $this-&gt;connect_database();
      $this-&gt;initialize_curl();

      // process the url
      $this-&gt;process_next_url_in_queue($url);

      // only non-SSL works at this point

      exit;

    // parent
    default:

      // seperate database and curl for the parent
      $this-&gt;connect_database();
      $this-&gt;initialize_curl();
      break;
  }
}
</code></pre>

<p>As you can see, I had to open and close the database connection so it would work and I am doing the same with CURL. Here is the code in <code>initialize_curl()</code>:</p>

<pre><code>$this-&gt;ch = curl_init();
curl_setopt($this-&gt;ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this-&gt;ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($this-&gt;ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($this-&gt;ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($this-&gt;ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($this-&gt;ch, CURLOPT_HEADER,         FALSE);
</code></pre>

<p>I am using <code>CURLOPT_SSL_VERIFYPEER</code> and <code>CURLOPT_SSL_VERIFYHOST</code> because without it my SSL CURL requests will fail. It's an issue with the server set up and not something I can change.</p>

<p>Wwhen a child CURL's an SSL URL, I think it fails because there is a problem with setting these options, but I don't know. If I set CURL to be verbose, I see the following error:</p>

<pre><code>* About to connect() to HOST port 443 (#0)
*   Trying IP... * connected
* Connected to HOST (IP) port 443 (#0)
* NSS error -8023
* Closing connection #0
* SSL connect error
</code></pre>

<p>Please let me know what I can do to make this work.</p>