Jump to content

Fatal fork error:


rofl90

Recommended Posts

error:

Fatal error: pcntl_fork() [<a href='function.pcntl-fork'>function.pcntl-fork</a>]: Error 12 in /opt/local/share/httpd/charlie/sample_fork.php on line 3

 

 

I'm new to forking so this might not even look like a fork but it was my attempt.

code:

<?php
set_time_limit(1000000000000);
$CONF = array();
$CONF["DATABASE"] 				= 'x';
$CONF["USERNAME"] 				= 'x';
$CONF["PASSWORD"] 				= 'x';
$CONF["HOST"] 					= 'x';
$CONF["FORKS"] 					= 34;
$pids 							= array();
mysql_connect($CONF["HOST"], $CONF["USERNAME"], $CONF["PASSWORD"]);
mysql_select_db($CONF["DATABASE"]);
$first = 100000;
$myFile = "tracking_info.txt";
$handle = fopen($myFile, 'a+') or die("Unable to open file");

while($first < 999999) {
$pids = pcntl_fork();
if($pid == -1) {
		die("Could not fork");
	}
	elseif ($pids) {
		$status = '';
		pcntl_waitpid($pids, $status);
	}
	else {
	$fileName = "http://www.x.com/x-g--d" . $first . ".html";
	if($file = file_get_contents($fileName)) {
		$match = array();
		if(preg_match('~<div id="ATTRACTION_REVIEW" class="listing">(.*?)</div><!--/ ATTRACTION_REVIEW\.listing-->~is', $file, $match)) {
			$match[1] = mysql_real_escape_string($match[1]);
			$result = mysql_query("INSERT INTO pages (linkName, theText) VALUES('$fileName', '$match[1]')") or die(mysql_error()); //important
			if($result) {
				fwrite($handle, "Node " . $first . ": Success\n\n");
				$first++;
			}
			else {
				fwrite($handle, "Node" . $first . ": Failed\n\n>");
			}
		}
		else {
			fwrite($handle, "Node" . $first . ": Not an attraction\n\n");
			$first++;
		}
	}
	else {
		$first++;
		fwrite($handle, "Could not open Node" . $first . "\n\n");
	}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/109923-fatal-fork-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.