Re: child process
| From: | Stuart Dallas | Date: | Fri, 16 Jan 2015 09:53:34 +0000 |
| Subject: | Re: child process | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324249@lists.php.net to get a copy of this message | ||
Please include the list when replying, or let me know where to send the invoice. And please don’t
top-post; it’s against the rules not to mention incredibly annoying: http://git.php.net/?p=php-src.git;a=blob_plain;f=README.MAILINGLIST_RULES;hb=HEAD
On Friday, Jan 16, 2015 at 9:43 am, nupur walia <nupur.wl@gmail.com>, wrote:
Hi,
I am trying to run a php process like 'php' path to php file. Its a magento extension that
used child processes to create product feeds. My code is :
$stdErr = Mage::getBaseDir('log') . '/fontis_feedsgenerator_subprocess.txt';
$descriptorSpec = array(
0 => array("pipe", "r"), // stdin is a pipe that the
child will read from
1 => array("pipe", "w"), // stdout is a pipe that
the child will write to
2 => array("file", $stdErr, "a") // stderr is a file
to write to
);
$pipes = array();
// Build child path from current file location and Magento path delimiter
$execPath = escapeshellarg(dirname(__FILE__) . DS . $this->CHILD_SCRIPT);
// Open child process with proc_open
//$this->log("Opening child: ".$exec_path);
$process = proc_open('php '.$execPath, $descriptorSpec, $pipes);
if (!is_resource($process)) {
$this->log("Error opening child process.");
fclose($pipes[0]);
} else {
// Write entity id/attribute info to pipe
$data = array(
"magento_path" => $this->info("base_dir"),
"store_id" => $this->info("store_id"),
"child_class" =>
Mage::getConfig()->getModelClassName($this->_childClass),
"entity_ids" => $this->_accumulator,
"attributes" => $this->_attributes,
"generate_categories" => $this->generateCategories,
"config_path" => $this->_configPath,
);
$this->_accumulator = array();
fwrite($pipes[0], json_encode($data));
fclose($pipes[0]);
// Read child's output until it finishes or child is no longer running
$result = '';
do {
$result .= fgets($pipes[1]);
$state = proc_get_status($process);
} while (!feof($pipes[1]) && $state['running']);
// read JSON-encoded data from child process
$batchData = json_decode($result, true);
if (is_array($batchData)) {
$this->populateFeedWithBatchData($batchData);
} else {
$this->log("Could not unserialize returned data from child to
array:");
$this->log($result);
$this->log($batchData);
}
// Close child process if it's still open
$status = proc_close($process);
}
// Close remaining file handles
@fclose($pipes[1]);
It read data and write to it some file. Using proc_open pipes. I dont know how to use curl for this
code?
Curl is not really applicable to what you’re doing.
You’re wanting to run PHP code from PHP code? There’s no need to run a new process for this,
simply include the code you want to run.. How easy that will be depends on what the PHP script
you’re including is trying to do, but there is rarely a reason to run a new instance of PHP from a
PHP script.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
On Fri, Jan 16, 2015 at 3:07 PM, Stuart Dallas <stuart@3ft9.com> wrote:
On Friday, Jan 16, 2015 at 9:15 am, nupur walia <nupur.wl@gmail.com>, wrote:
I am using proc_open in my code but this function is disabled on my server.
Can you please tell me if there is any other function that i can use in
place of proc_open?
Can i use curl in place of proc_open? If yes then please let me know how
can i use curl to replace proc_open?
What are you actually trying to do?
If you’re trying to make an HTTP request (as implied by your question) you can use the curl
extension if it’s installed: http://php.net/curl. If not there
are probably other way to accomplish what you’re trying to do, but we’ll need details to be able
to help any further.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/