Jump to content

sneskid

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Everything posted by sneskid

  1. don't worry about the code, it's the url syntax that im asking about. Say you ping "www.electionsites.ca" from the command prompt in windows. you'll get a reply from 74.52.10.226. Now if you use a browser to visit "http://74.52.10.226" you will see a cPanel screen not electionsites.ca, because the server hosts more than one domain. my question is how to access the site using the ip syntax. Something like "http://74.52.10.226/electionsites/"?
  2. I'm trying to write a script that can connect to a domain using it's IP address. But I'm dealing with a multi-domain server, so the IP address needs an additional string describing which domain I want to access. I've seen it done before but forgot the syntax. It's an apache server with cPanel. Help? Thanks.
  3. I've always been raised to believe ( I make it sound religious almost ) that: x++ means: take x as is, at this moment in time (not later) and apply that value in the current operation (one would expect the compiler to be using temporary variables at this point) THEN immediately increment it by 1. THEN continue with the rest of the operation. ++x means: increment x by 1 NOW, THEN use the new value, THEN continue the operation. operation: be it arithmetic, function calls, array index assignments, echo messages, whatever. Thus 42 and 56 are as expected. and $x=1; echo add($x++,$x++); should echo 3 and leave $x as 3. (and it does, yay) But I'm sure we can all agree that $x=1; $a[$x] = $x++; should be $a[1] = 1 NOT $a[2] = 1; (which I would accept if this was legal: $a[&$x] = $x++ and leave $x=2 So 4.3.10 has it right, and 5.1.4 got lazy? This behavior says "yea, I'll check that variable later, saves memory, PHP is way too bloated... who cares about the foundation of programming as we know it." and I have an issue with that, the kind of issue that makes me want to divorce PHP and marry Perl.
  4. (v5.1.4) function xyz(&$v){$v++;return $v;} $a = array(); $b=0; $a[$b] = $b++; // [1]=>int(0) $a[$b] = ++$b; // [2]=>int(2) $a[$b] = xyz($b); // [3]=>int(3) $a[$c=$b] = xyz($b); // [3]=>int(4) $c negates the bug|feature var_dump($a); When $b is altered on the right side, it alters the expected assign-to index of $a on the left side. This shows that the left side evaluation can be effected after the right side evaluation. In other languages, for example Javascript, $a[$b] would have first been evaluated&locked as $a[0].
  5. in case you are wondering, i tried having the & at the function params too, no effect. Having the function create the "array workaround" makes things nicer and more transparent: function abc(&$v=0){ static $r=array(); if($v) $r[]=&$v; // or just $r = array('test'=>&$v); else var_dump($r); } $test1 = 'hello'; $test2 = 'stuff'; abc($test1); abc($test2); $test1 = 'bye'; $test2 = 'things'; abc();
  6. say you have this: function abc($v=0){ static $r; if($v) $r = &$v; var_dump($r); } $test = 'hello'; abc(&$test); $test = 'bye'; abc(); output: string(5) "hello" NULL should be: string(5) "hello" string(3) "bye" Was this done for security reasons? or is it just a PHP limitation? Although less convenient, this bug can be worked around like so: function abc($v=0){ static $r; if($v) $r = $v; var_dump($r['test']); } $test = 'hello'; abc(array('test'=>&$test)); $test = 'bye'; abc(); output: string(5) "hello" string(3) "bye" So why won't static variable retain a direct reference??
  7. [quote author=thorpe link=topic=124065.msg513664#msg513664 date=1169773177] You cant catch parse errors. In fact you can't catch php generated errors. The best you could do would be..... [code] <?php try {   if (!@eval('will cause error')) {     throw new exception('unknown error');   } } catch (Exception $e) {   echo 'Caught exception: '.$e->getMessage()."\n"; } ?> [/code] Which I'm sure is not really what you want to hear. Ive always thought the same myself, not being able to catch php's exceptions.... then whats the point? [/quote] Thanks Thorpe Yea the PHP try/catch system is weak
  8. [quote author=konnwat link=topic=124065.msg513580#msg513580 date=1169764776] [code]<?php try { eval('will cause error'); } catch (Exception $e) {   echo 'Caught exception: '.$e->getMessage()."\n"; } ?>[/code] try that ^^ [/quote] yea, that doesn't work. it won't execute anything inside the catch block, but still raises the parse error, i want to catch that error. im using php 5.1.4
  9. in Javascript one can easily do the following: <script type="text/javascript"> try { eval('will cause error'); } catch(e) { alert(e); } </script> in PHP the try catch system is only for errors thrown by your code, seems like I can't catch errors thrown by PHP. <?php try { eval('will cause error'); } catch (Exception $e) {   echo 'Caught exception: ',  $e->getMessage(), "\n"; } ?> Sadly that wont work, really limits the whole try/catch concept. Any other ways I can achieve a Javascript like functionality?
  10. when you include/require from inside a function (or any nested structure for that matter) does the included file context start at the top level, or as a continuation of the structure where it was included? From what i can tell they start at the top level. Can someone just confirm that for me. Thanks
  11. I ran this string as a shell command: $cmd = 'ps -o%mem,rss,pid | grep ' . getmypid(); It shows the mem usage. I ran it in a bare script and it showed it's using just over 7000 kb of mem, 0.7% or total memory. I guess the server has 1gig memory. This seemed like a large chunk of memory for a bare bone script to be using, so I made a huge array(range(1, 10000)) to see if the mem usage jumped, just to make sure this was the right process. It spiked up by 800kb. The question I have... isn't 7 megs rather much for a bare script process to take up?? How does php run each script? Does it start them as their own process, or as a thread from the main php process, or does what I just typed make me sound like a total noob. Thanks for any insight, feel free to include extra details, nerd talk is my friend.
  12. my concern with the solution you presented was the needless memory usage it comes with (although it's better than scandir, according to this http://bugs.php.net/bug.php?id=31515) Thanks though. I'll have to devise some sort of indexing scheme or something.
  13. I've read all the typical mumbo jumbo on directory scanning and counting content, but it seems like the more practical stuff is missing. 1: The rewinddir function is nice... but is there a fast way to arbitrarily jump dir position? (like what fseek is to files) Would this somehow be possible with the resource context param?     2: Shouldn't the Count of contents in a directry be kept as a value by the system? Would save time otherwise wasted on iterating through. 3: Hypothetically, if there are millions of files in a directory, are you screwed? Thanks for any help.
  14. Is there any guarantee in the order in which php scripts run. I know if I tell the script to sleep, or do a database query, other scripts will still run unbothered. Is each script technically a seperate process? Is it possible that the system may decide to put a script on pause for a bit and execute a section of another script before coming back to the first one? Thanks
  15. i've read that using the self keyword can have a drawback when classes inherit other. does using the 'this' keyword work around that? what is the main difference between the 2. thanks
  16. I'm clear on that. but why did he use { } what's the difference between myClass->myFunction(); myClass->{myFunction()}; when is it appropriate to use {} in this context
  17. I read that "Sometimes PHP programmers need to use "{" and "}" to resolve ambiguity" The example wasn't enough. I'm currently going through someone elses code, and they use {} in the following syntax // this code is part of a class function called "urldecodeRecursively" $d = new stdClass(); foreach ($data as $key => $val) { if ($key != urldecode($key)) { [b]$d->{urldecode($key)}[/b] = $this->urldecodeRecursively($val); } else { [b]$d->{$key}[/b] = $this->urldecodeRecursively($val); } } return $d; // I'm just curious about the $d->{stuff} Could someone shed some light on that? thanks.
  18. I'm interested in having PHP processes communicate and share resources (for example a DB connection). I've done some testing and it seems that even persistent DB connections are created on a per-process-basis (even if simultaniously running PHP processes are accessing the same DB with the same credentials). I say this because in my test the connection resource IDs were different... but then again they may reference the same connection behind the scenes. I have no way of knowing for sure, it would be nice if it were clerified. Here is an example of what I'd like to achieve: { - Start 1 PHP script that will create and keep alive a database connection, a "master" script. It may even have a registry system. It may even check if an instance of itself is already running, so it will not run again. It's mainly for sharing DB connection, and communication among mini-php-processes (ex. from clients visiting the web page). - As people use the website, they will ofcourse spawn php processes. These processes will check for the master script and use it, in essence, as a portal. They can share data and common resources that don't need to be duplicated (like a database connection). } I'm aware there are security issues, testing nightmares and who knows what else at risk with this model. But I'd like to know my options when it comes to php process-level communication. I've read the singleton patter, I've read the registry pattern, they only help in the current process. They aren't truely global. (atleast in the context of the article I was shown) Thank you in advance for any advice, prayers, references & clerification.
  19. I've considered the database/txt file options, and would like to avoid them if possible. Actually I don't mind the database way as much. But I need something with less overhead. It would be nice to just share data in memory through some kind of super global array. (in order to avoid reading from the HD every time) How would I go about setting up this application wide object.
  20. thats helps but my major question is how to allow php scripts running at the same time to share data. (say 10 people access the site at the same time) i could use a database to lug data back and forth, but there has to be an easier way
  21. if i use static variables in a class, will that only take effect for class instances within the current script, or will the value be accross all php script running at the same time which have included that class?
  22. What is the max length of an ASCII string that sha1 should be given? I'm assuming it's 20 characters.
  23. awesome! thanks! what did . and .. mean again I know one of them was to go to the previous directory and the other was to go to the very root.. or something like that.
  24. Hey, I'd like to make myself a php script that can scan directories for files and folders. Basically a directory browsing script To be honest I havn't looked hard yet for this on the web, but if someone can point me to the right functions that would be really cool & save me some time.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.