| Message |
|
MightyThor
Trainee Developer
Joined: 24 Aug 2005
Posts: 8
0 Cash
|
 Access Violation
Hi,
I'm getting the error
"PHP has encountered an Access Violation at XXXXXXX..."
with a site I'm working on.
It happens on occasion when I load a page but not all of the time.
Is this is a problem with my code or is it a problem with my web server?
Cheers.
|
| Wed Aug 24, 2005 10:46 am |
|
 |
|
|
Dem0n
Site Admin
Joined: 05 Jul 2005
Posts: 237
528 Cash
|
Does it say the error was on a line? Or just say access violation? Are you sure that your host has php enables?
|
| Sun Aug 28, 2005 12:53 pm |
|
 |
MightyThor
Trainee Developer
Joined: 24 Aug 2005
Posts: 8
0 Cash
|
The message seems to have actually gone now.
Everything was fine for days then suddenly the server seemed to come down and when it came back up, I was getting that Access Violation at random points in the site.
I'm assuming that since it's gone away, it was a problem on the hosting company's end.
Cheers.
|
| Wed Aug 31, 2005 3:35 am |
|
 |
Outkast
Developer
Joined: 13 Aug 2005
Posts: 92
Location: Boston, MA 0 Cash
|
It sounds like more of a server problem than a code problem.. can you post the PHP script that was giving you this error?
|
| Sun Sep 04, 2005 8:19 pm |
|
 |
MightyThor
Trainee Developer
Joined: 24 Aug 2005
Posts: 8
0 Cash
|
It was quite a large site but it started happening after I created a class and instantiated it on a page like this:
include('resource/include/global.php');
include('resource/include/page.php');
$page = new page($_GET['section'], $_GET['page'], $db);
echo $page->title;
etc.
The $db varaible is my PEAR db connection.
I thought it might have something to do with the fact that many instances of the object were being created but I wasn't destroying them.
Cheers.
|
| Mon Sep 05, 2005 3:15 am |
|
 |
Outkast
Developer
Joined: 13 Aug 2005
Posts: 92
Location: Boston, MA 0 Cash
|
Yeah that could definitely do it. The server probably ran out of data memory space for these objects if you do not destroy them properly.
|
| Mon Sep 05, 2005 11:50 am |
|
 |
MightyThor
Trainee Developer
Joined: 24 Aug 2005
Posts: 8
0 Cash
|
How do I destroy an object properly?
Currently I have the function:
function destroy()
{
settype(&$this, 'null');
}
Would this do it? Would I just call this at the end of each my scripts?
I heard that the usual deconstructor was flawed and didn't always work properly.
Any ideas?
Cheers.
|
| Tue Sep 06, 2005 2:35 am |
|
 |
|
|
Outkast
Developer
Joined: 13 Aug 2005
Posts: 92
Location: Boston, MA 0 Cash
|
You can just use the unset() variable just as any other variable. So to delete the object named Object1 use
Code:
unset( Object1 );
The unset function will determine that it is an object and call the objects destructor function.
Hope that helps.
|
| Tue Sep 06, 2005 11:09 am |
|
 |
MightyThor
Trainee Developer
Joined: 24 Aug 2005
Posts: 8
0 Cash
|
Thanks for the help.
I've included a footer to make sure the page objects which I create are destroyed properly.
However, I've got a question about sessions and the use of objects within them.
I have a user login and authentication script set up. The authentication script checks the login details and, if they are correct, instantiates a user object with information about that user. The object is then made available through a session.
Code looks like this:
while( $row = $result->fetchrow(DB_FETCHMODE_ASSOC) )
{
if($_POST['username']==$row[username] && $_POST['password']==$row[password])
{
$user = new user($row[user_id], $row[username], $row[password], $row[firstname], $row[surname], $row[department], $row[email]);
$_SESSION['valid_user'] = $user;
}
}
When the user logs out, I destroy sessions using session_destroy() but as far as I'm aware, this won't unset the object variable will it?
Where do I do this? In the logout script or at the end of the authentication script once the session has been made?
Cheers.
|
| Wed Sep 07, 2005 3:07 am |
|
 |
Outkast
Developer
Joined: 13 Aug 2005
Posts: 92
Location: Boston, MA 0 Cash
|
You would want to do this in the logout script. What object are you talking about unsetting? The $_SESSION array? If so, you can use the unset() function to do this as well when the user logs out before you call session_destroy( ).
|
| Wed Sep 07, 2005 7:16 am |
|
 |
MightyThor
Trainee Developer
Joined: 24 Aug 2005
Posts: 8
0 Cash
|
Sorry, I mean destroying the $user instance I created in the script before putting it into the session.
Where do I kill that? In the script or when the user logs out?
|
| Wed Sep 07, 2005 7:31 am |
|
 |
|
|