Page 1 of 1

What can make a php file stop its execution?

Posted: Fri Jul 01, 2011 3:47 pm
by fguerrero
Hello
I am new to php, I have been debugging a php code and I am facing a problem that it making me crazy :banghead: .

The program runs fine, until it enters to the _instantiateController method. Once inside this method, the parameters that the method receives are printed, then I print the message Factory.php 2.18, so far everything is running as expected, then given the parameters values, It doesn't enter to the first and second IFs (this is fine, that is what I am expecting ), but then I am expecting the message Factory.php 2.20-01, but I don get it. the last thing that I get is the message Factory.php 2.18.

How can this be possible????? Why is it stopping there? Could this be a problem in my code, or a bad php server installation?

Code: Select all


function _instantiateController($file, $class, $aParams = null)
    {

	print("$file  <br />");
	print(" $class <br />");
	print("$aParams <br />");
	print("Factory.php 2.18 <br />");
        if (!@include_once $file)
        {
	    print("Factory.php 2.18-01 <br />");
            $errMsg = "OA_Admin_Statistics_Factory::_instantiateController() Unable to locate " . basename($file);
	    print("Factory.php 2.19 <br />");
            return MAX::raiseError($errMsg, MAX_ERROR_INVALIDARGS);
        }
        if (!class_exists($class)) 
        {
	    print("Factory.php 2.19-01 <br />");
            $errMsg = "OA_Admin_Statistics_Factory::_instantiateController() Class {$class} doesn't exist";
	    print("Factory.php 2.20 <br />");
            return MAX::raiseError($errMsg, MAX_ERROR_INVALIDARGS);
        }
	print("Factory.php 2.20-01 <br />");
        $oController = new $class($aParams);
	print("Factory.php 2.21 <br />");
	print(" $oController  <br />");
        return $oController;
    } 



Thanks in advance

Re: What can make a php file stop its execution?

Posted: Fri Jul 01, 2011 4:33 pm
by Bill H
You don't say much about $file, but it is going to try to include that file. Depending on its inability to find that file, or any problems it might have in attempting to include it, the script might very well time out without any message. i.e. Your server message sets a time limit for a script to execute, and if the script exceeds that time limit it simply quits.

Re: What can make a php file stop its execution?

Posted: Fri Jul 01, 2011 4:53 pm
by fguerrero
Thanks Bill,

I didn't know that PHP's behavior, I will keep that in mind. But this make me have more questions

When I print $file, I get the full path to my file and also when I print $class I get the class name that it is inside the file. So those are exactly the file and class that I want to use (I am getting the right path to my file, and my file is there), so if the file was not included, Wouldn't the program display the message print("Factory.php 2.18-01 <br />")???

Is there any way to know if the program is not finding the file and running out of time? or is the any other way to debug a PHP code?

I don't know php very well, I am thinking as a Java and C programmer, I don't have experience with PHP, so this problem doesn't make sense to me.

Thanks for your time

Re: What can make a php file stop its execution?

Posted: Fri Jul 01, 2011 6:15 pm
by califdon
Add these 2 temporary lines at the beginning of the PHP code (after the opening <?php tag). Then remove those lines before you put the script into production (they might give helpful diagnostic information to a hacker):

Code: Select all

ini_set("display_errors", 1);
ERROR_REPORTING(E_ALL);

Re: What can make a php file stop its execution?

Posted: Sat Jul 02, 2011 8:52 am
by Bill H
Wouldn't the program display the message print("Factory.php 2.18-01")???
Not if the script timed out in the process of attempting to make the inclusion. Turning on error reporting as Don suggested might clarify things, because it should then tell you it timed out and the script and line number that caused the time out. But even with error reporting turned on I have had scripts time out without messages. I think it depends a bit on the server.

Re: What can make a php file stop its execution?

Posted: Sat Jul 02, 2011 1:05 pm
by construct

Re: What can make a php file stop its execution?

Posted: Sat Jul 02, 2011 4:25 pm
by McInfo
fguerrero wrote:

Code: Select all

if (!@include_once $file)
Because of the error control operator (@), all errors that might be triggered by include_once are suppressed, regardless of the error_reporting level.
construct wrote:error_reporting(1);
1 is equal to E_ERROR.

Code: Select all

+---------------------+-----------------------------------------+---------+
| PHP Code            | Binary                                  | Decimal |
+---------------------+-----------------------------------------+---------+
| E_ERROR             | .... .... .... .... .... .... .... ...1 |       1 |
| E_WARNING           | .... .... .... .... .... .... .... ..1. |       2 |
| E_PARSE             | .... .... .... .... .... .... .... .1.. |       4 |
| E_NOTICE            | .... .... .... .... .... .... .... 1... |       8 |
| E_CORE_ERROR        | .... .... .... .... .... .... ...1 .... |      16 |
| E_CORE_WARNING      | .... .... .... .... .... .... ..1. .... |      32 |
| E_COMPILE_ERROR     | .... .... .... .... .... .... .1.. .... |      64 |
| E_COMPILE_WARNING   | .... .... .... .... .... .... 1... .... |     128 |
| E_USER_ERROR        | .... .... .... .... .... ...1 .... .... |     256 |
| E_USER_WARNING      | .... .... .... .... .... ..1. .... .... |     512 |
| E_USER_NOTICE       | .... .... .... .... .... .1.. .... .... |    1024 |
| E_STRICT            | .... .... .... .... .... 1... .... .... |    2048 |
| E_RECOVERABLE_ERROR | .... .... .... .... ...1 .... .... .... |    4096 |
| E_DEPRECATED        | .... .... .... .... ..1. .... .... .... |    8192 |
| E_USER_DEPRECATED   | .... .... .... .... .1.. .... .... .... |   16384 |
| E_ALL               | .... .... .... .... .111 .111 1111 1111 |   30719 |
| E_ALL | E_STRICT    | .... .... .... .... .111 1111 1111 1111 |   32767 |
| ~0                  | 1111 1111 1111 1111 1111 1111 1111 1111 |      -1 |
+---------------------+-----------------------------------------+---------+

PHP Version: 5.3.2

Re: What can make a php file stop its execution?

Posted: Sun Jul 03, 2011 8:21 pm
by Bill H
Because of the error control operator (@),
:lol: :banghead: I read that code snippet and completely missed that. :oops:

Re: What can make a php file stop its execution?

Posted: Tue Jul 05, 2011 4:42 pm
by fguerrero
Thank all of you, This information was very helpful