PHP Resource ID reporting

  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

When I load my page it reports Resource id #653 at the top of the page. My page is working like it should and I have searched and searched through my script to see where a mysql_query (mysql_fetch_array, mysql_num_rows, etc) call is messing up, but all my queries work and none of them depend on any variables. I guess I need 1 of 2 things.

1. Can I safely turn off that Resource id report in php.ini?

2. Does that resource id number tell me anything that can help me track down which query(ies) are messing up?


I'd rather not provide code yet cause there's a ton of it, but I am wondering if there's some nice methodology that someone has for fixing this or getting around it.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

It's going to be one of the mysql functions which returns a "resource" type that is the culprit.

For instance, mysql_connect returns a "resource" type.

Quote:
resource mysql_connect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int $client_flags = 0 ]]]]] )


Any of the other MySQL functions which return a resource rather than a PHP data type could also be the cause.

mysql_query is another example.

Quote:
resource mysql_query ( string $query [, resource $link_identifier ] )


"resource id #nn" is what you get if you convert a "resource" to a string, which is what happens when you try to print/etc the resource.

What I think is happening, is that you may be assigning the result from one of these resource returning functions to a variable somewhere, for example,

PHP Code: [ Select ]
$conn = mysql_connect(...);


Then, somewhere along the line the variable is being printed. Maybe for a debugging purpose that someone missed during a cleanup.

--

What I would do is go through the list of MySQL functions and gather tha names of everything that returns a resource type. That should narrow down the suspects considerably.

Then, I would grep/findstr the scripts files looking for these function names. Making sure to include filenames and line numbers in my grep/findstr output so I can go directly to the spot and inspect it.

If you pipe the output for your grep/findstr search to another file, you'll have a nice list if places in the code you can inspect one by one. You will likely be able to rule out quite a few of them just by looking at the line in the grep/findstr output.
  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

working on it. It would be nice if the resource id actually meant something. Anyway, I'll see what I can find.
  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

The whole script runs inside a function. No variables get echoed/printed, only one variable at the end gets returned. Does this resource have to be printed/echoed in order to be showing?
  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

Quote:
Then, somewhere along the line the variable is being printed. Maybe for a debugging purpose that someone missed during a cleanup.


I got it fixed. A resource was getting appended to my return variable. Once you said it's getting printed then that actually narrowed it down for me. I think when the app was first being built the function was simple and returned an $r 'meaning result' straight from the single, simple query. Once more queries started being added, the new queries retained the $r variable for their result from mysql_query, but then at the end of the function the calculations were performed and formatted and returned in the old, retained variable $r .= so all the resources got appended to that final $r.

Actually, I'm pretty bad myself about reusing variables cause I've heard that lowers the memory usage of a php script and over the years it has worsen, but this is the first times it's bitten me. When I first started out programming I'd always create a new, unique variable name for everything. Of course, that got taxing having to come up with variable names and a pain to keep them in order. Well, this could be one argument against reusing variables especially query variables, but still doesn't compare with the arguments I've read over the years as to reusing them. I figured you'd like this cause it seems you're always interested in what methods/functions run faster, better, etc per some of your other posts I've read.

Thanks joebert. It's all fixed up.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I'm not entirely sure where the resource ID comes from. My best guess is that every call to a resource returning function increments a counter and that's where it comes from.

Meaning, the initial connect would use #1, the first query would return #2. A query in a loop could jump the counter up to #100 before it got to the next resource returning function.

I don't know though. I took a quick glance in the PHP source for "resource id" thinking I could find a printf style mask. I came up empty though. It will probably be worth looking into one of these days.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 123 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.