The online racing simulator
Eh, I don't think this is a apache error. The question you should ask your self is, is there any other part of the script that is not using that function? From what I can see, I don't think you have a function setup for this. Try a setup like this . . .



<?php 
php

function get_lfsw_data($query_str) {
    
sleep(5);
    if (
$gzstr file_get_contents('http://lfsworld.net/pubstat/get_stat2.php?version=1.3&c=2'.$query_str)) { 
        if (
$str = @gzuncompress($gzstr)) 
            return 
$str;
        else
            die(
$gzstr);
    } else {
        return -
1;
    }
}

echo 
get_lfsw_data('&action=wr&idk=".$this->id_key);

?>


I would do it this way, I'm not fully sure how your doing it by yourself. Also note that sleep(5) some times returns the error of 'not enough time between querys' so you might want to bump it up to 6 seconds.
I'm stunned. :Eyecrazy:

It works, basically with your function. But as hard as I try, I can see no difference (in principle) to my old code. The only change is that now there is this extra function that does the querying.

Maybe I just have overseen something.


<?php 
    
function get_lfsw_data($query_str) {
        
sleep(6);
        
$query "http://lfsworld.net/pubstat/get_stat2.php?version=1.3".$query_str."&c=2&idk=".$this->id_key;
        if (
$gzstr file_get_contents($query)) {
            if (
$str = @gzuncompress($gzstr)){
                return 
$str;
            }else{
                die(
$gzstr);
            }
        } else {
            return 
"";
        }
    }
?>

Quote from HorsePower :It works, basically with your function. But as hard as I try, I can see no difference (in principle) to my old code. The only change is that now there is this extra function that does the querying.

There are some oddities in PHP, sometimes it doesn't work as line-by-line as you'd expect, might've found one of those.
To wrap this off-topic discussion up, I just want to say that everything is working fine now. Just as you guys here I have written some kind of SDK, basically a class covering some helpful functions for querying LFSW.

Furthermore I have written another class, called 'tracker', which uses the class above to get all HLs, PBs and WRs of a set of mates and stores them into a MySQL DB. There are some functions for a formatted output in a table.

The result can be seen here.

There are still some things to implement or some bug fixes to make, I guess.

Anyway, I will write a bit of documentation for all my stuff and release it on our homepage (or even somewhere here) in the near future. Maybe you guys are also interested in this tracker stuff.

Again, I want to thank you for the kind help here.

BTW: I don't want to compete with you guys. I believe your SDK is much more stable, bug free and runs on a wider range of platforms, since I really haven't cared much about compatibility and I'm not a PHP expert.
Hey, i am trying to get the list of teams. But it seems the parsing is going wrong. I already added some output to show me the raw string returned from lfsworld and this looks good. But there is something going wrong with the unpack stuff which i dont really understand (beeing a php noob )
Does anyone experience the same problems?

To be a bit more clear - i am using this small script derived from your examples:
Quote :
function teams_test() {
global $LFSWorld;
$teams = $LFSWorld->get_teams();
echo "<p>Starting teams list</p>\n";
foreach ($teams as $this_team) {
echo "-----------------------------------------\n";
echo "Team: {$this_team['team']} ({$this_team['tag']}) \n\n";
echo "Members: {$this_team['nr_members']} \n";
echo "Website: {$this_team['url']} \n\n";
}
echo "<p>Finished teams list</p>\n";
}

It is not related to tarpitting or my UserID. Other things i tried (get pbs/hotlaps etc.) work fine.
Quote from MikeB :Hey, i am trying to get the list of teams. But it seems the parsing is going wrong. I already added some output to show me the raw string returned from lfsworld and this looks good. But there is something going wrong with the unpack stuff which i dont really understand (beeing a php noob )
Does anyone experience the same problems?

To be a bit more clear - i am using this small script derived from your examples:

It is not related to tarpitting or my UserID. Other things i tried (get pbs/hotlaps etc.) work fine.

I'll look into this in a moment. . . I've got some SimFIA stuff to do right now. Could you tell me what version of the script your running?
Quote from Dygear :I'll look into this in a moment. . . I've got some SimFIA stuff to do right now. Could you tell me what version of the script your running?

The file says:
@version $Id: LFSWorldSDK.php,v 1.4 2006/11/10 20:38:36 lur Exp $

And the package name is "lfsworldsdk-php4-cvs20061110".

Thanks

<?php 
$teams 
$LFSWorld->get_teams();
echo 
"<p>Starting teams list</p>\n";
foreach (
$teams as $this_team) {
    echo 
"-----------------------------------------\n";
    echo 
"Team: {$this_team['team']} ({$this_team['tag']}) \n\n";
    echo 
"Members: {$this_team['nr_members']} \n";
    echo 
"Website: {$this_team['url']} \n\n";
}
echo 
"<p>Finished teams list</p>\n";
?>

Seems that when you place it inside a function like that, it simply will not work. I'm running 5.2.0 on my test box (and production box) and the issue remains. I would simpley extend the lfsworld class with your own functions.
Quote from Dygear :I would simpley extend the lfsworld class with your own functions.

Just to clarify as this sounds hopelessly complex for someone who's new to it.

Instead of wrapping actions into a function like MikeB did in the example a few posts above, a much cleaner and actually simpler method is extending lfsworldsdk.

include 'lfsworldsdk.php';

class MyLFSWorld extends LFSWorldSDK {
function teams_test() {
$teams = [B]$this[/B]->get_teams();
echo "<p>Starting teams list</p>\n";
foreach ($teams as $this_team) {
echo "-----------------------------------------\n";
echo "Team: {$this_team['team']} ({$this_team['tag']}) \n\n";
echo "Members: {$this_team['nr_members']} \n";
echo "Website: {$this_team['url']} \n\n";
}
echo "<p>Finished teams list</p>\n";
}
}

By doing this you are effectively copying the entire function set from lfsworldsdk and adding the teams_test function to it. The passing around of $LFSWorld is replaced with $this, $this is always a reference to the object itself when working with code inside a class.

Finally you would use your class instead of lfsworldsdk when creating the object:

<?php 
//$LFSWorld = new LFSWorldSDK();
$LFSWorld = new MyLFSWorld();
$LFSWorld->teams_test();
?>

Quote from Dygear :

<?php 
$teams 
$LFSWorld->get_teams();
echo 
"<p>Starting teams list</p>\n";
foreach (
$teams as $this_team) {
    echo 
"-----------------------------------------\n";
    echo 
"Team: {$this_team['team']} ({$this_team['tag']}) \n\n";
    echo 
"Members: {$this_team['nr_members']} \n";
    echo 
"Website: {$this_team['url']} \n\n";
}
echo 
"<p>Finished teams list</p>\n";
?>

Seems that when you place it inside a function like that, it simply will not work. I'm running 5.2.0 on my test box (and production box) and the issue remains. I would simpley extend the lfsworld class with your own functions.

Your code to decompress c=1 doesn't work (on my box at least), and is a bit nasty anyway.
This works just as well...


<?php 
return gzinflate(substr($str10));
?>

I can't replicate the error you and MikeB are talking about so I can't offer any solutions. However, scope should not matter. It doesn't matter if you are in calling from a function or a global scope, the code should still behave the same. (For reference I'm running Apache 2.0.59 w/ PHP5.2.0)

Extending LFSWorldSDK in that manner is very bad design form and could just be a work around to a more serious issue.
Quote from Anarchi-H :Extending LFSWorldSDK in that manner is very bad design form and could just be a work around to a more serious issue.

What makes it bad design?
Quote from filur :What makes it bad design?

Misuse of inheritance and in the specific example, mixing (business) logic with presentation. A quote from the great wiki itself in the 'Common Mistakes' section.
Quote from Wikipedia :Object-oriented programming
Overuse of inheritance when composition or aggregation may be more appropriate. It has been suggested that training materials over-emphasizes inheritance, perhaps because it is easier to illustrate than the alternatives.

In this case, aggregation would be more appropriate if you are going to extend it with OO.
I understand it is difficult to to explain the concept of a class to new coders, let alone the difference between ways of extending them but education is key and in this case it is showing new coders the wrong way to do it.

The code doesn't work in that configuration for a reason. It may not be your fault, it may be a PHP bug, but regardless it is your responsibility as the developers to find it, and even more so if you can replicate it!
You wouldn't expect Scawen to say "It just doesnt work, here is what you'll have to do instead".

Sorry for the lecture, but you did ask
Quote from Anarchi-H :Misuse of inheritance and in the specific example, mixing (business) logic with presentation. [...] In this case, aggregation would be more appropriate if you are going to extend it with OO.

While i do agree on mixing code with presentation, i would suggest pretty much anything to avoid passing the object around as a global variable.

I guess by misuse of inheritance you're saying inheritance is in this case completely unecessary, if so i would basically agree. However, attempting to explain classes, objects and association or how to use runkit doesn't really fit in this thread. Extending the class is an easy neatness fix, and in my opinion quite a good introduction to objects and classes in PHP. If there's enough interest i'm sure the manual and google would do a better job of teaching object orientation then i could.

Quote :You wouldn't expect Scawen to say "It just doesnt work, here is what you'll have to do instead".

I would expect Scawen to say "until i fix the black screen bug, don't start LFS in fullscreen" (might've been windowed).
Quote from filur :While i do agree on mixing code with presentation, i would suggest pretty much anything to avoid passing the object around as a global variable.

I guess by misuse of inheritance you're saying inheritance is in this case completely unecessary, if so i would basically agree. ...

Not quite; if I were to aggregate an instance of LFSWorld to MyLFSWorld it would look like this;


<?php 
php
class MyLFSWorld
{
    var 
$LFSWorld null;
    function 
MyLFSWorld($idk)
    {
        
$this->LFSWorld =& new LFSWorldSDK($idk);
    }
}
?>

I'm not sure where you got the idea of global from
The definition of an aggregation is when one object belongs to another, and this owned object will be created and destroyed with/by the owning object.
As you can see, it is a minor departure from inheritance, but an important one because you no longer have to worry about namespace clashes between the base lib and the "extended" functionality, and (with PHP5) you don't have to worry about them accidentally accessing a protected var. (Not that this applies here )

Quote from filur :I would expect Scawen to say "until i fix the black screen bug, don't start LFS in fullscreen" (might've been windowed).

Fair play, but I bet it would be high on his list
Quote from Anarchi-H :I'm not sure where you got the idea of global from

From the code i used in my example, the code that was being discussed by MikeB and Dygear.

Quote from Anarchi-H :As you can see, it is a minor departure from inheritance

Actually, i see it as something completely different.
Ahem, before this evolves to some flamewar maybe some background to my question :-)
Basically i am currently playing around with the pubstats and just wanted to test the different methods your SDK is offering. Having studied computer science and about 5 years of C++ experience in full depth in my job I have quite some knowledge of object orientation and the related paradigms :-)
So i totally agree that my code sample using global vars sucks So please do not take it as a serious approach for anything useful - i really just played with your SDK methods (and PHP in general).

(Now back to topic )
Having said that, i would agree with Anarchi:
Quote :However, scope should not matter. It doesn't matter if you are in calling from a function or a global scope, the code should still behave the same.

As i said i have no experience with PHP sof ar. I am using php5 as installed by my ISP. Is there anything useful i could do to help track this error down?
Quote from MikeB :
As i said i have no experience with PHP sof ar. I am using php5 as installed by my ISP. Is there anything useful i could do to help track this error down?

You can in fact. First thing you can do is try to replace

<?php 
global $LFSWorld;
?>

by

<?php 
global &$LFSWorld;
?>

Else PHP could try to create a copy of the $LFSWorld object instead of passing a reference to it to the function.

If this does not work, try giving $LFSWorld as a parameter to your function:

<?php 
function get_lfsw_teams(&$LFSWorld) {
  
// ...
}

$LFSWorld = new LFSWorldSDK($idk);
get_lfsw_teams(&$LFSWorld);
?>

This should work in every case.

Greets
Quote from St4Lk3R :.. PHP could try to create a copy of the $LFSWorld object instead of passing a reference to it to the function.

PHP5 should AFAIK always pass objects by reference.
Quote from filur :PHP5 should AFAIK always pass objects by reference.

PHP 5 does, but PHP 4 may want to do bad things with the objects.
I just started playing around with this SDK. I noticed that when I get my PBs all the lapcounts are wrong. I looked at the data recieved back from world and it is correct, but when reading the results return by the function they are wrong. For example 43 becomes 4, 167 becomes 1. Has anyone else noticed this?

I should note that I changed the pubstats version to 1.3 from 1.2 and added my ident key. I got the same results both when using compressed and uncompress LFSWorld queries.
Quote from bdshan :I just started playing around with this SDK. I noticed that when I get my PBs all the lapcounts are wrong. I looked at the data recieved back from world and it is correct, but when reading the results return by the function they are wrong. For example 43 becomes 4, 167 becomes 1. Has anyone else noticed this?

I should note that I changed the pubstats version to 1.3 from 1.2 and added my ident key. I got the same results both when using compressed and uncompress LFSWorld queries.

I got exactly the same problem. I resolved it using a simple "explode" statement instead of regex matching - i did not investigate further but I suppose filur/dygear had some reason to use regex instead of explode?
I am currently at work, i can post the change this evening if you need it.
Thanks for the offer, MikeB. I know that explode will work. I currently use it in my implementation. I was looking at integrating the SDK so I wouldn't need to rewrite all those same functions myself.

I am completely clueless when it comes to regex, so I was hoping filur or dygear would give an explaination of why they use the regex and what it is doing.
Only bit of regex i can think of was added to grab usernames with any number of spaces, discussed earlier in this thread. A limited explode is probably a better option.
Filur, indulge me if you will. What does

preg_match_all('/(.+)\s(.+)\s(.+)\s(.+)/U', $data, $fragment);

do? This line is the only line in the PB function that I don't understand. And forgive me I have not looked up the preg_match function in the PHP manual.

FGED GREDG RDFGDR GSFDG