Page 1 of 1

popen and include files

Posted: Wed Jul 08, 2009 5:39 am
by bestsurfer
I have a php file which is executed with popen.

I am using an include in that file to get config variables. The config file included is a class.

Code: Select all

class config
{
    function config()
    {
      // Database related configurations
        $this->db_engine      = 'mysql';
        $this->db_username  = 'root';
        $this->db_password  = '';
   }
}
If I include the file and try to retrive the config values using

Code: Select all

$cfg=new config();
Apache hangs and the CPU usage shoots to 100%.

If I remove the config file and use something like :

Code: Select all

    $cfg->db_engine      = 'mysql';
    $cfg->db_username  = 'root';
    $cfg->db_password  = '';
Everything is fine.

Even when using an include, if I run the script via command line and not through popen, everything is fine.

Could you please suggest whats wrong here?

The popen call is

Code: Select all

$proc = popen('php ' . $path . $file . ' ' . $args . ' &', 'r');
Thanks

Ashish

Re: popen and include files

Posted: Wed Jul 08, 2009 5:43 am
by SvanteH
Have you declare the variables in the config class? Also there is a __construct() you can/should(?) use instead for class creation method.

You could also try using require_once to parse the file.

Re: popen and include files

Posted: Wed Jul 08, 2009 5:48 am
by bestsurfer
Havent declared all variables, I will try doing that now. I had used the __construct thing before, did not work.

If the problem is "declaring" variables, the script should not run via the command line too right?

Anyways will try declaring them and return with results.

Thanks
Ashish

Re: popen and include files

Posted: Wed Jul 08, 2009 5:53 am
by SvanteH
Probably not but still might aswell notify all errors I can see so they get fixed ;) Tell me the results.

Could you also do an

Code: Select all

echo 'php ' . $path . $file . ' ' . $args . ' &'
?

Re: popen and include files

Posted: Wed Jul 08, 2009 6:22 am
by bestsurfer
Hi,

Tried declaring all variables, used __construct() still nothing.

The output of echo you asked for is:

Code: Select all

php /var/www/codebase/web/resize.php '/' '600' '250'

Code: Select all

error_log("conf start config.php".date('h:i:s'));
require_once("/var/www/codebase/web/config.php");
$cfg=new conf();
error_log("conf done config.php".date('h:i:s'));
Never reaches the 4th line. All errors and notices are on, and there are no notices or errors.

Thanks

Re: popen and include files

Posted: Wed Jul 08, 2009 6:28 am
by SvanteH
Are you sure that you're displaying all errors?

Code: Select all

 error_reporting(E_ALL);
 ini_set('display_errors', 1);

Re: popen and include files

Posted: Wed Jul 08, 2009 6:32 am
by bestsurfer
Yes I am watching them with tail, I have set log errors to syslog and the error level is set to E_ALL

:|

Re: popen and include files

Posted: Wed Jul 08, 2009 6:35 am
by SvanteH
I'm a bit stumped, did you have two problems or one?
You can try exec() if you are trying to run a PHP script that way

Re: popen and include files

Posted: Wed Jul 08, 2009 6:46 am
by bestsurfer
Yes works with exec() , but I might need a pointer to input some stuff later on.

Anyways, I will go with exec() for now. Thanks for your time and help

Regards,
Ashish