What can make a php file stop its execution?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
fguerrero
Forum Newbie
Posts: 4
Joined: Fri Jul 01, 2011 3:34 pm

What can make a php file stop its execution?

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

Post 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.
fguerrero
Forum Newbie
Posts: 4
Joined: Fri Jul 01, 2011 3:34 pm

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

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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);
Last edited by califdon on Sat Jul 02, 2011 11:25 am, edited 1 time in total.
Reason: To correct the 2nd argument to ini_set()
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

Post 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.
construct
Forum Newbie
Posts: 5
Joined: Sat Jul 02, 2011 12:58 pm

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

Post by construct »

User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

Post by Bill H »

Because of the error control operator (@),
:lol: :banghead: I read that code snippet and completely missed that. :oops:
fguerrero
Forum Newbie
Posts: 4
Joined: Fri Jul 01, 2011 3:34 pm

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

Post by fguerrero »

Thank all of you, This information was very helpful
Post Reply