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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

that is the child.php. run the script like usual..

we need to see if argv holds anything. by using $_SERVER['argv'];

We're basicly debugging

but just run the script like you normally do.

 

Also, can i get your php version?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.