popen and include files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bestsurfer
Forum Newbie
Posts: 5
Joined: Wed Jul 08, 2009 5:25 am

popen and include files

Post 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
Last edited by bestsurfer on Wed Jul 08, 2009 5:48 am, edited 1 time in total.
SvanteH
Forum Commoner
Posts: 50
Joined: Wed Jul 08, 2009 12:25 am

Re: popen and include files

Post 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.
bestsurfer
Forum Newbie
Posts: 5
Joined: Wed Jul 08, 2009 5:25 am

Re: popen and include files

Post 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
SvanteH
Forum Commoner
Posts: 50
Joined: Wed Jul 08, 2009 12:25 am

Re: popen and include files

Post 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 . ' &'
?
bestsurfer
Forum Newbie
Posts: 5
Joined: Wed Jul 08, 2009 5:25 am

Re: popen and include files

Post 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
SvanteH
Forum Commoner
Posts: 50
Joined: Wed Jul 08, 2009 12:25 am

Re: popen and include files

Post by SvanteH »

Are you sure that you're displaying all errors?

Code: Select all

 error_reporting(E_ALL);
 ini_set('display_errors', 1);
bestsurfer
Forum Newbie
Posts: 5
Joined: Wed Jul 08, 2009 5:25 am

Re: popen and include files

Post 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

:|
SvanteH
Forum Commoner
Posts: 50
Joined: Wed Jul 08, 2009 12:25 am

Re: popen and include files

Post 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
bestsurfer
Forum Newbie
Posts: 5
Joined: Wed Jul 08, 2009 5:25 am

Re: popen and include files

Post 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
Post Reply