Jump to content

jefftanner

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jefftanner's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I dumbfounded as to why the following code - is_null( $array['foo'] ) fails to parse: [pre] if ( is_null( $parsed['text_product_ids'] ) { $parsed['text_product_ids'] = '5, 6, 7, 8, 9, 10'; } [/pre] But this succeeds to be parsed and executes: [pre] $showSelectedProducts = $parsed['text_product_ids']; if ( is_null( $showSelectedProducts ) ) { $parsed['text_product_ids'] = '5, 6, 7, 8, 9, 10'; } [/pre] Just curious -- Jeff in Seattle
  2. I am using PHP process controls, and I want to get a "human readable" string based upon exit status. Is there such a function? Example code: $cid = pcntl_wait($status); //Protect against Zombie children print "we are in parent $pid post wait child $cid AFTER\n"; print "pid child $cid -- status $status.\n"; if(pcntl_wifexited($status)) { $exit_code = pcntl_wexitstatus($status); print "pid child $cid returned exit code: $exit_code.\n"; } else if (pcntl_wifstopped($status)) { $stop_signal = pcntl_wstopsig($status); print "pid child $cid is currently stopped: $stop_signal.\n"; } else if (pcntl_wifsignaled($status)) { $terminate_signal = pcntl_wtermsig($status); print "pid child $cid terminated due to a signal $terminate_signal.\n"; } else { print "child $cid was unnaturally terminated.\n"; } So for each of these stopped, terminated, and exit codes, I want an interpretation in string form.
  3. QUESTION: If pcntl_exec() fails (returns FALSE), then is there any way to get the reason (exit code) why what executed had failed? To start, if I try to execute an non-existent command "garbage" in the command line, then it fails with an exit code of 127: $ garbage bash: garbage: command not found $ echo $? 127 Next, I have a very simple php script test_exit.php: <?php exit(127); ?> And I try to execute in the command line, then it also fails with an exit code of 127: $ php test_exit.php $ echo $? 127 Now I want to try the previous executions using PHP process controls: pcntl_fork, pcntl_exec, and pcntl_wait, etc... My PHP process controls test script is as follows test_pcntl.php: <?php switch ($cid = pcntl_fork()) { case -1: die('could not fork'); case 0: // Child Fork, set alarm and execute command pcntl_alarm(60); $cid = getmypid(); print "we are in pid child $cid BEFORE\n"; $result = pcntl_exec($pathBinaryExecutable, $args); print "we are in pid child $cid AFTER, indicating that pcntl_exec() failed.\n"; print "pid child $cid pcntl_exec() result: " . var_export( $result, TRUE ) . "\n"; break; default: // Parent Fork, wait for return of child process $cid = pcntl_wait($status); if(pcntl_wifexited($status)) { $exit_code = pcntl_wexitstatus($status); print "pid child $cid returned exit code: $exit_code.\n"; } else if (pcntl_wifstopped($status)) { $stop_signal = pcntl_wstopsig($status); print "pid child $cid is currently stopped: $stop_signal.\n"; } else if (pcntl_wifsignaled($status)) { $terminate_signal = pcntl_wtermsig($status); print "pid child $cid terminated due to a signal $terminate_signal.\n"; } else { print "child $cid was unnaturally terminated.\n"; } } ?> If in the Child fork, pcntl_exec() is passed php script test_exit.php: $pathBinaryExecutable = "/usr/local/bin/php"; $args = array( "/home/jeff/public_html/php/test_exit.php" ); Then execution of this test script will return the expected exit code of 127: $ php test_pcntl.php we are in pid child 23512 BEFORE we are in parent 23511 pre wait child 23512 BEFORE we are in parent 23511 post wait child 23512 AFTER pid child 23512 -- status 32512. pid child 23512 returned exit code: 127. Now if in the Child fork, pcntl_exec() is passed the non-existent command garbage: $pathBinaryExecutable = "garbage"; $args = array(); Then execution of this test script does not return the expected exit code of 127: $ php test_pcntl.php we are in pid child 23609 BEFORE we are in pid child 23609 AFTER, indicating that pcntl_exec() failed. pid child 23609 pcntl_exec() result: false we are in parent 23608 pre wait child 23609 BEFORE we are in parent 23608 post wait child 23609 AFTER pid child 23609 -- status 0. pid child 23609 returned exit code: 0 So, at this point, the parent process thinks that the child process has succeeded because the exit code is zero (0), and not the expected 127. What can I do to my code to determine why pcntl_exec() had failed, AND to determine why pcntl_wait() did not return an exit status of 127? Thanks -- Jeff in Seattle
  4. Explain resolving problem by 'redirect'? Is this what you mean?: $mysql_cmd = "mysql -u {$target_db['user']} -p{$target_db['passwd']} -h {$target_db['host']}"; $sql_file = "prep_angelfish.sql"; $last_line = system($mysql_cmd . " < " . $sql_file, $return_value); if ( $last_line === FALSE ) { exit ($return_value); } I would prefer to avoid this approach since its error report from MySQL would be muted. Thanks, Jeff in Seattle
  5. How for example? Reference: http://www.phpfreaks.com/forums/index.php/topic,175470.0.html I have tried through PHP/mysqli. but calling MySQL "Source" command fails: $target_dbh->query("SOURCE prep_angelfish.sql") Query error: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SOURCE prep_angelfish.sql' at line 1. -- Jeff in Seattle
  6. I am having a problem with MySQL 'SOURCE' command when called through PHP 5.1 mysqli instance. PHP Version 5.1.4, mysqli module: Client API library version 5.0.38 MySQL Version 5.1.22-rc-community My SQL command is "SOURCE prep_angelfish.sql", which works through the MySQL command prompt, but not when called through a PHP/mysqli query. Calling from MySQL command prompt: mysql> SOURCE prep_angelfish.sql; Query OK, 0 rows affected (0.00 sec) Calling through PHP: $target_dbh->query("SOURCE prep_angelfish.sql") Query error: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SOURCE prep_angelfish.sql' at line 1. $sql_file = "prep_angelfish.sql"; if ( !file_exists($sql_file) ) { print "Error: $sql_file does not exist!\n"; exit (1); } @$target_dbh = new mysqli($target_db['host'], $target_db['user'], $target_db['passwd']); if (mysqli_connect_errno()) { print "Connect failure: Target host " . $target_db['host'] . " connection error: (" . mysqli_connect_errno() . ") " . mysqli_connect_error() . "\n"; exit(mysqli_connect_errno()); } $mysql_query = "SOURCE $sql_file" ; if ( $target_dbh->query($mysql_query) !== TRUE ) { print "Query failure on: " . $target_db['host'] . "\n"; print "Query: \"$mysql_query\"\n"; print "Query error: (" . $target_dbh->errno . ") " . $target_dbh->error . ".\n"; exit($target_dbh->errno); } Thanks, any ideas??? Jeff in Seattle
  7. Now I want to take it one step further, I want a PHP script to use a php.ini file within a specific sub-directory under DirectoryRoot "/websites/site/foo/root/". For example; php.ini is located within "/websites/site/foo/root/bar/". Either I would like to modify local apache2 config at /websites/etc/apache2.d/foo.conf by adding a new Directory directive specifically for "/websites/site/foo/root/bar/", but I am not sure what to add: <Directory "/websites/site/foo/root/bar/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all {PHP INI PATH directive here???} </Directory> I tried adding php_ini_path "/websites/site/foo/root/bar/" within this Directory directive, but upon apache2 restart, it did not recognize php_ini_path and failed restart. OR I also googled and read about an environment variable PHPRC which is expected to be added a .htaccess file. Within "/websites/site/foo/root/bar", I created a .htaccess file with the following single line: SetEnv PHPRC "/websites/site/foo/root/bar/" This also did not work. When calling http://foo.dd.dev/bar/phpinfo.php, it used the php.ini file declared by PHPINIDir "/websites/site/foo/root/" and not the php.ini file declared within "/websites/site/foo/root/bar". Any suggests for finer resolution for choosing a php.ini within a sub-directory within DirectoryRoot? Thanks
  8. After Googling, I discovered PHPINIDir, but it was not documented on http://www.php.net/docs.php. When I modified local apache2 config at /websites/etc/apache2.d/foo.conf: <VirtualHost *> ServerName foo.dd.dev DocumentRoot "/websites/site/foo/root/" DirectoryIndex index.php index.html index.htm PHPINIDir "/websites/site/foo/root/" <Directory "/websites/site/foo/root/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> And call to http://foo.dd.dev/phpinfo.php shows that it is using local php.ini file installed within DocumentRoot: Configuration File (php.ini) Path => /websites/site/foo/root/php.ini So this worked.
  9. Standard install: At tail of /etc/apache2/apache2.conf: LoadModule php5_module /usr/lib/apache2/modules/libphp5.so DirectoryIndex index.php index.html AddType application/x-httpd-php .php AddType application/x-httpd-php .phtml AddType application/x-httpd-php .php3 AddType application/x-httpd-php .php4 AddType application/x-httpd-php .html AddType application/x-httpd-php-source .phps # Include the virtual host configurations: Include /etc/apache2/sites-enabled/[^.#]* Include /websites/etc/apache.d/*.conf And a local apache2 config at /websites/etc/apache2.d/foo.conf: <VirtualHost *> ServerName foo.dd.dev DocumentRoot "/websites/site/foo/root/" DirectoryIndex index.php index.html index.htm <Directory "/websites/site/foo/root/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> At /etc/hosts: 127.0.0.1 localhost 100.10.10.10 foo.dd.dev
  10. My configuration PHP is standard with php.ini file within /etc/php5/apache2/php.ini and a copy in /etc/php5/cli/php.ini. Now I need to have a local php.ini file used when calling a PHP script that resides within the same directory as the php.ini file. For example, my setup is as follows: /websites/site/foo/root/php.ini /websites/site/foo/root/phpinfo.php DocumentRoot is /websites/site/foo/root ServerName is foo.dd.dev If I go to directory /websites/site/foo/root/, and then call from command line php -i, it shows that it is using the local php.ini file: Configuration File (php.ini) Path => /websites/site/foo/root/php.ini However, if I call http://foo.dd.dev/phpinfo.php, it shows that this PHP script is using the default apache2 php.ini file instead of the local php.ini from where phpinfo.php is called: Configuration File (php.ini) Path => /etc/php5/apache2/php.ini Any ideas of what I am missing? Thanks
×
×
  • 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.