Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
Yeah, you could mimic a task scheduling system manually using PHP to logging when it was last run and if it's over an hour ago then run it. It pretty much requires that you have constant traffic, however.
-
You should always be running APC (or at least some sort of opcode cache) in a production environment. It'll speed up things up considerably. It's also nice being able to cache things in memory instead of on the disk.
-
Just echo something. That will per definition be an HTTP response when it's served via a web server.
-
With what?
-
Yeah I'd agree it's better practice, but strictly speaking it's not required.
-
Depending on the version of PHP. No. I assume you're talking about PHP 4's lack of visibility keywords, but in PHP 4 the constructor was not called __construct(). Actually, public is optional for methods because things by default are public.
-
Yeah, but to be honest, I consider that a bug more than a feature. When $bar('something') is callable, then $foo->bar('something') should be as well (assuming both refer to anonymous functions).
-
class Foo {} $foo = new Foo(); $foo->bar = function() { echo 'test'; }; I wouldn't recommend that kind of code though. Javascript uses prototype based object orientation while PHP uses class based object orientation.
-
Activating xml rpc using a php.ini
Daniel0 replied to SeeeD's topic in PHP Installation and Configuration
If you're running PHP as (Fast)CGI you won't need to restart, but if you're running as an Apache module you have to (but you probably can't on shared hosting). I would say that your best bet is to convince your host to install that extension, or get a VPS if you have special needs. Shared hosting is rarely very good if you need a custom setup. -
Does anyone know a good way of blocking ads in Chrome? I tried both AdSweep and AdBlock+, but both of them suck. Is there anything that works as well as AdBlock Plus for Firefox? I changed from Firefox to Chrome because Firefox was becoming too slow. Basically it would become really sluggish when it reached 400 MB memory usage (which was pretty often). The only thing I really miss is proper ad blocking.
-
Activating xml rpc using a php.ini
Daniel0 replied to SeeeD's topic in PHP Installation and Configuration
Something like this should do it: extension=php_xmlrpc.so (or .dll if it's a Windows box) This assumes that php_xmlrpc.so is in the directory specified by the extension_dir directive. -
Activating xml rpc using a php.ini
Daniel0 replied to SeeeD's topic in PHP Installation and Configuration
You need to put extension=path where path is the path the path to the extension you wish to load. You can also just uncomment the line that probably already exists in your php.ini. -
Why it does that depends on how you've written your code. Maybe you don't clean up unused resources. That's simple to fix. Just do manual garbage collection. Maybe you wrote your script recursively and the call stack keeps growing. In that case, you could refactor it to be tail recursive. Maybe you're just trying to keep all the generated data in memory. In that case, write it to permanent storage more frequently.
-
[SOLVED] Trying to understand double dollar sign $$variable global
Daniel0 replied to scanreg's topic in PHP Coding Help
Well, you can see it like this: $GetVar is substituted with CarMake, so you end up with $CarMake. It's essentially because a variable in PHP can have any name that can be represented using the string data type, so you can also do stupid shit like this: <?php $hello = 'test'; ${'this is a ' . $hello} = 'foo'; $bar = 'this is a test'; echo $$bar; -
[SOLVED] Trying to understand double dollar sign $$variable global
Daniel0 replied to scanreg's topic in PHP Coding Help
Nevermind the performance, it makes your code almost entirely unreadable. -
Right, that means your query failed, so you'll have to fix it. You could try echoing the query and see if it's generated correctly. You would also want to fix the SQL injection using mysql_real_escape_string, but that's unrelated to the error.
-
Your query failed for some reason. Use mysql_error to see what error message MySQL returned.
-
When asking people for help when getting an error, it's often a good idea telling what the error is.
-
A NULL value would be better to represent the tree root because it specifically means that no such thing exists. When using InnoDB's referential integrity features, you would also get into trouble representing "no parent" with a numeric value (unless there is an object with ID 0 called "The Universe").
-
There is no need for recursion: $db = new PDO('mysql:host=localhost;dbname=test', 'root', 'foo'); $res = $db->query('SELECT s.sname, c.cname FROM state AS s LEFT JOIN city AS c ON s.sid = c.state_id ORDER BY s.sname, c.cname'); $prevStateName = null; foreach ($res->fetchAll() as $city) { if ($city['sname'] !== $prevStateName) { echo $city['sname'] . PHP_EOL; } if ($city['cname'] !== null) { echo ' - ' . $city['cname'] . PHP_EOL; } $prevStateName = $city['sname']; } Output: Aruba Australia India - Delhi - Karnataka Netherlands Russia - TamilNadu
-
If [imath]y=x^3[/imath] then the angle between the x-axis and the line between the origin and the point (x,y) must be given by: [math]A(x) = \arctan \left( \frac{y}{x} \right) = \arctan \left( \frac{x^3}{x} \right) = \arctan \left( x^2 \right)[/math] Then when we find the derivative: [math]A'(x) = \frac{1}{\left(x^2\right)^2 + 1} \cdot 2x = \frac{2x}{x^4 + 1}[/math] So when [imath]x=2[/imath] the rate of change of the angle is [imath]A'(2) = \frac{4}{17} \approx 0.235294[/imath].
-
You can use curl.
-
Yeah, but nobody writes code like that anyway. It's an example that wouldn't appear in real applications. You might for instance make sort of integrity check, or you might later want to abstract it away using a strategy or you might want to use a proxy. You cannot do that if you're directly accessing your properties.