Jump to content

requinix

Administrators
  • Posts

    15,229
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. If you make changes to the database then that means changes to the underlying file, right? You can know if there were changes if the timestamp changes.
  2. This is really just templating. Just about any templating solution will work. Do you really want the input and template files to be valid PHP code? Doesn't seem like a good idea to me. I mean, it's not like you can execute them as they are now. How about simpler stuff like (input.ini) colour = "brown" animal = "cat" (template.php.tpl) <?php echo "<p>This is a {{colour}} $animal.</p>"; <?php $variables = parse_ini_file("input.ini"); $template = file_get_contents("template.php.tpl"); $pairs = array(); foreach ($variables as $name => $value) { $pairs["{{" . $name . "}}"] = $value; } echo strtr($template, $pairs);
  3. Modification time of the SQLite file?
  4. The public one. You know, for sharing publicly. With the public.
  5. Timestamp. Versioning. Deltas. Stuff like that. Hashes can tell you that something changed but won't help you identify what it was.
  6. "$resp->Ack" would only have worked if was a child of the root element. Sounds like it wasn't, but I can't be sure because you didn't post the XML you're working with.
  7. 1. The PHP is irrelevant. Only the HTML it outputs matters. 2. Actually it kinda does. Those three selectors are all essentially "if"s: if this matches, or if that matches, or if the other one matches, then...
  8. If you're taking the approach of putting an ID on the body then you can do everything with pure CSS. <body id="home"> <ul id="menu"> <li id="menu-home"> <a href="/index">Home</a> </li> </ul> /* something along the lines of */ body#home #menu #menu-home a, body#foo #menu #menu-foo a, body#bar #menu #menu-bar a { whatever; }
  9. Because that's all the "simple" syntax allows: one property. If you're looking for a rationale from the PHP developers as to why only one property indirection is permitted then you're probably going to have to ask them directly. [edit] Ohhh, you mean why is it an error. Not why is it not allowed. Nevermind.
  10. Right, they're the same for particular types of items, but not for all items. That means the data structure will have to vary somehow, and you can accomplish that with a JSON string or by creating an arbitrary array. To refine the example I gave earlier, <input type="hidden" name="items[0]" value="door"> <input type="hidden" name="options[0][opening]" value="chain"> <input type="hidden" name="options[0][numwindows]" value="2"> <input type="hidden" name="options[0][storey]" value="1">0 is the first item added to the order. It is a "door". The door comes with multiple options, which arrive in your code as an array in $_POST. $option_keys = array( "door" => array("opening", "numwindows", "storey") ); $items = array(); foreach ($_POST["items"] as $n => $type) { if (!isset($option_keys[$type])) { // error: invalid item type continue; } $item = array("type" => $type, "options" => array()); if (isset($_POST["options"][$n])) { // extract options from the form and validate against $option_keys $item["options"] = array_intersect_key($_POST["options"][$n], array_flip($option_keys[$type])); if (count($item["options"]) != count($option_keys[$type])) { // error: not all options set in form continue; } } $items[$n] = $item; } // $items = array( // 0 => array( // type => "door", // options => array( // opening => "chain", // numwindows => 2, // storey => 1 // ) // ) // )The JSON option isn't that much different. <input type="hidden" name="items[0][type]" value="door"> <input type="hidden" name="items[0][options]" value="{"opening":"chain","numwindows":2,"storey":1}"> $option_keys = array( "door" => array("opening", "numwindows", "storey") ); $items = array(); foreach ($_POST["items"] as $n => $item) { if (!isset($item["type"], $option_keys[$item["type"]])) { // error: invalid item type continue; } if (!isset($item["options"])) { $item["options"] = array(); } // extract options from the form and validate against $option_keys $options = array_intersect_key($item["options"], array_flip($option_keys[$item["type"]])); if (count($options) != count($option_keys[$item["type"]])) { // error: not all options set in form continue; } $item["options"] = $options; $items[$n] = $item; } // $items = array( // 0 => array( // type => "door", // options => array( // opening => "chain", // numwindows => 2, // storey => 1 // ) // ) // )And there are multiple variations possible for both of those, depending on what's easiest to work with both in the Javascript and the PHP.
  11. JSON might be useful if the inputs vary a lot - like there isn't a consistent structure every time you prompt for particular details regarding an item. Make sure to validate it on the next page so that someone can't tamper with the data before submitting the form. The normal answer is to use arrays, which could also help here but probably isn't the only thing you need. <input type="hidden" name="whatever[]" value="1"> <input type="hidden" name="whatever[]" value="2"> <input type="hidden" name="whatever[]" value="3">and $_POST["whatever"] is an array.
  12. Compare $data between the working and non-working versions to find out what the difference is.
  13. An easy way to determine which file the user is looking at would be basename($_SERVER["REQUEST_FILENAME"])That'll be "index.php" or "index-02.php" or whatever. Put that value into a variable then test it for each of the links: if it matches then show the class, otherwise don't. class="active">01
  14. :/ It's running from within PHP so why would it be not be affected by PHP settings?
  15. On how to do... what? There are multiple options here that you should do some research on and think about before jumping right into the code.
  16. Either change the link so that it takes them to the purchase page, or make the download link redirect the user (with or without a warning) to the purchase page. When they buy it, redirect them back to the initial page they were on - the one with the link they clicked. If it's not obvious, you never link to the actual music file. Downloads should always be handled by a PHP script which authenticates the user before directly outputting the music file. Really the music itself shouldn't be located anywhere on your server in a place that someone could access it over the web.
  17. Step 3: copy the data. Where's the confusion?
  18. Referring to the last line: $streamStatus = $obj->isConnected?'true':'false';
  19. As the docs say, brpoplpush - which you can read as a "b"locking "r"ight "pop" and "l"eft "push" - deals with two lists, and moves one element from one to the other. If all you need is a simple queue with blocking then do lpush+brpop or rpush+blpop (whichever "direction" makes most sense to you).
  20. Anecdotally and without any sort of source to back me up, you shouldn't do an indefinite timeout on a blocking function. I think that's from personal experience. Do a "long" timeout of less than a minute, then worst case your loop just jumps back to the start and it starts blocking again immediately.
  21. You lost the CURLOPT_RETURNTRANSFER option from your first post. Need that.
  22. Measure the time yourself. $start = time(); whatever loop { $remaining = $limit - (time() - $start); blocking function with timeout of $remaining if possible if function timed out or time() > $start + $limit then die }
  23. The formatting doesn't matter - those two JSON samples are equivalent. $obj is an object by default. You can work with that just fine. It doesn't have to be an array. But if you really want an array then check the documentation that Barand linked to.
  24. Are you running PHP from the same machine that you tried with the browser? A timeout suggests the connection is blocked, like by a firewall.
  25. Then rather than watching a file try message queues: process that receives the AJAX requests sends a message to a queue while the processes that talk to clients wait (again, with blocking) for a message to arrive on their particular queue. Software like Redis and (IIRC) Memcached can also do blocking queues, if you have anything like that already in place. If the data is small then the message could contain it, otherwise all it has to do is act as a signal that the receiving process needs to check the database. Point is to avoid polling.
×
×
  • 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.