Jump to content

New webhost behaving strangely :(


d.shankar

Recommended Posts

Hi all !

 

I had this forking script with php running fine. But today i moved to a new host, but the parameter is not getting fetched.

 

The main concept behind the code is EXEC() forking.

we have 2 files parent.php and child.php.

 

the parent.php when executed creates a file and registers the time in the file it began and forks a child process and gets exited. the child process now executes and registers its time and then exits.

 

These things work fine but the parameter i send from the parent process is not getting feched to the child process. but the same script is running in other servers.

 

 

parent.php

 

<?php
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging
//echo exec('whoami');

$book="god";

  exec("child.php testing $book > /dev/null 2>&1 &");

  if ($fp = fopen("log.txt", "a"))
{
   fwrite($fp, "Parent process finished at ".date("H:i:s", time())."!\n");
  fclose($fp);
}



?>

 

 

Child.php

 

<?php

error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging

  sleep(5);
  if ($fp = fopen("log.txt", "a"))
{
   fwrite($fp, "Child process $argv[1] $argv[2] finished at ".date("H:i:s", time())."!\n");
   fclose($fp);
}
?>

 

 

I am waiting... Thanks

Link to comment
https://forums.phpfreaks.com/topic/176376-new-webhost-behaving-strangely/
Share on other sites

Thanks for replyin ProXy_

 

I aint getting any errors

 

The expected result is

Parent process finished at 7:03:45

Child process testing god finished at 7:03:50

 

FYI : testing and god are the variables i send from parent.php

 

 

 

The result i get now is

Parent process finished at 7:03:45

Child process  finished at 7:03:50

 

 

The variables are not getting printed.

ok, i would try this then..

 

Parent

<?php
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging
//echo exec('whoami');

$book="god";

  exec("child.php testing $book > /dev/null 2>&1 &");

$fp = fopen("log.txt", "a");

   fwrite($fp, "Parent process finished at ".date("H:i:s", time())."!\n");
  fclose($fp);




?>

 

 

Child

<?php

error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging

  sleep(5);
$fp = fopen("log.txt", "a");
   fwrite($fp, "Child process $argv[1] $argv[2] finished at ".date("H:i:s", time())."!\n");
   fclose($fp);
?>

 

 

hopefully this helps.

I removed the if statement, its not a loop.

 

Basicly your saying if $fp = "blah" then: save information..

But your not previously calling $fp to be anything at all..

 

therefor its not going to do anything but sit there unless your leaving code out

and your calling $fp somewhere down the line to be log.txt

Actually i was asking where is  $argv[1] $argv[2] being called from?

 

if you notice in child.php where  $argv[1] $argv[2] it prints the spaces.

thats because  $argv[1] $argv[2] doesn't equal anything.

 

So i did a little research with $argv and i here is a link i'll send you to

that should explain everything you need

 

only thing i can think of is your current host doesn't have

register_argc_argv enabled.

 

you can read more about it here:

http://www.php.net/manual/en/ini.core.php#ini.register-argc-argv

ok, as i'm doing research on this

Lets try this.

 

 

child.php

<?php
$argv=$_SERVER['argv'];
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging

  sleep(5);
  if ($fp = fopen("log.txt", "a"))
{
   fwrite($fp, "Child process $argv finished at ".date("H:i:s", time())."!\n");
   fclose($fp);
}
?>

 

this is only testing

but lets see what that does.

Very possible. and also it seems from research that PHP 4.3+ won't support alot of commands sent through $argv

 

wich is why i asked your php version.

and hosts can disable use of argv commands or Command line scripting period.

but i won't stop i'll keep up with the research and get your answer :)

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.