Jump to content

johnsmith153

Members
  • Posts

    709
  • Joined

  • Last visited

About johnsmith153

  • Birthday 03/09/1996

Profile Information

  • Gender
    Not Telling

johnsmith153's Achievements

Advanced Member

Advanced Member (4/5)

2

Reputation

  1. I need to log details in PHP of analytics and usage. I'm looking at various possibilities: - Google Analytics server-side - segment.io - Just adding a record to a DB with PHP My concern is how much additional processing this will take on my server. Of course Google Analytics' JavaScript implementation won't use anything on my server, but my server-side method of course will. I also notice that on https://segment.io/docs/integrations/google-analytics they mention that "Server-side Google Analytics is being deprecated due to difficulty of use" - what does this mean? So basically, I want to implement some basic analytics storing (count number of hits to a URL + some other basic info) server-side - what's the best way to do this considering all things? It seems that adding a record to the DB every page view might be a little too much.
  2. Symfony2 specifically gives me problems because of its setup. I am getting this error: PHP Fatal error: Call to a member function get() on a non-object in /symfony-path/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php on line 252 I get this whenever I attempt to test a controller that returns either a rendered Twig template or when I use a controller that uses a service (and that doesn't return a rendered Twig template). So I'm trying to test controllers, but other than basic PHP it doesn't seem possible. Is there anything I can do? Is there a way of the controllers being able to access the services? Also, no doubt I'm going to have problems when I try running database queries. Unless I resolve this I see no point in Unit Testing. I'm sure there's an easy solution.
  3. I want to run certain tasks in the background and not on user request (e.g. send a transactional email and then based on the response do another action). If I had a script which added this info to a database: - PHP class - PHP method - parameters to pass to that method - etc. ..and then every 5 minutes one Cron Task retrieved all the data from this database and executed those tasks (using class, method and params), is this secure? It sounds a great idea to me. I could just store details of any class and method (and params) and have it run later. If there was only one or two tasks then I suppose I could just write a specific script and execute as a Cron Task, but this gives me flexibility to run anything.
  4. I want to create a Twig extension and use this: {{ new_func(route-name) }} To do the same thing as: {{ render_esi(url(route-name)) }} ...but with some adjustments (relating to caching, but that's not important). It's nearly done but it's this line that needs to be changed, but I can't see how I can call an ESI from this code (outside of Twig): return $environment->render($route); /// needs to receive route and render an ESI The code: namespace Acme\Bundle\MyBundle\Twig; class NewTwigFunction extends \Twig_Extension { private $request; public function __construct($container) { $this->request = $container->get('request'); } public function getFunctions() { return array('new_func' => new \Twig_Function_Method($this, 'newFunction', array('needs_environment' => true) )); } public function newFunction(\Twig_Environment $environment, $route) { return $environment->render($route); } public function getName() { return "new_func"; } }
  5. I'm using Symfony2's reverse proxy cache (all default settings etc.), so I want to integrate it with that, but even non-Symfony users will be able to help. My example below changes certain headers (so not PHP related), but it may need to be changes in PHP or Symfony2 code that gets the actual result. Any help at all may help to solve what has become a very difficult problem. The site in question allows for a 'basic' site view by scaling down images and removing JavaScript. As the content is the same I have used the same URL, but of course caching is an issue. I need to be able to cache them separately (or just ensure the cache is cleared). I have tried changing the Vary header which normally I have set to: Vary: Accept-Encoding ..and have set it to either: Vary: Accept-Encoding, basic ..or: Vary: Accept-Encoding, normal That actually works brilliant in Chrome on Mac, but Safari ignores the extra part of the Vary header. I stopped checking other browsers at this point. Any advice, either caching related or Symfony2 related?
  6. This question relates to using Symfony2 without APC. My web host is a shared cloud environment and apparently using APC is not currently possible. This is the only caching they offer: http://www.rackspace.com/knowledge_center/article/cloud-sites-php-op-code-cache When I asked about APC they pointed me to the above link, but of course that doesn't mean this is a substitute for APC. My understanding is that Symfony2 without APC can be very slow. My question is: will using the caching methods in the link above make up in any way for the speed loss that I believe will occur without using APC? Of course moving web host is possible, but that depends on how much their caching method makes up for the lack of APC. If this can't be answered then as much info as possible to enable me to question my web host further would help. Thanks
  7. Thanks for the advice. I still think Symfony 2 is a good choice, although I was under the impression Symfony2 wasn't considered light-weight. Regardless, I like what I see so far. John
  8. I have a site written in bad code. Everything is all thrown onto one page. The PHP is at the top (above HTML output) and the rest is at the bottom, but that's as good as it gets. Which framework would allow integration of this site the best (or any advice as to doing this)? Of course the whole lot could be re-written and of course I could just decide not integrate it, but I'm looking to improve all the client side stuff, but maybe just drop the PHP into one 'processing' file. The benefit to this I see is that I can gradually add improvements to the site and make use of the framework as I do it (and save time now). Over time the rubbish code would no doubt be reduced. Also, I may re-do all database interaction. So the idea would be to start as though creating a completely new site (using the framework), but when it gets to writing PHP I would save a lot of time by just calling the flat-PHP code already produced, maybe changing one or two things though (e.g. DB interaction). I'm sort of looking at learning Symfony2, so I suppose the question also is could I learn Symfony2 and then integrate this rubbish site later and kill two birds with one stone, or is Symfony2 not very good for integrating rubbish flat-PHP code (and maybe another framework is a better idea)? The idea is to modernise it, but not re-do it - if possible. Thanks for any advice.
  9. Are there any particular negatives of using Symfony 2 (over say another framework)? I have never looked at it before, but thought I might give it a try. What are the 'known' bad points? Obviously there are many positives, but any negatives will help me decide if to put the time towards this. Obviously I could just dive in, but as (like everybody) my time is limited (I'm learning other non-programming things) I want to do some research first. If I do look at it, I want to know enough to create a full application, not just to play around. I've done plenty of research, but there's nothing better than asking a regular user of it. I've heard that it isn't very extensible. Is this true? Are there any particular parts that another framework does so much better? I'm aware it's considered difficult to learn, but I'm sure I can get past that with hard work. Any other advice regarding starting out with Symfony2 would be appreciated. Thanks for any help.
  10. I'm pretty sure she wants to send one email, not a list of email addresses. I think if you read it again and see the form at the very, very end of her post (and code) you'll see what I mean. The form asks to select an option in a dropdown and those options relate to her array of email addresses. The error is no doubt as Jessica pointed out in post #2, which I'm guessing she would have solved. There may be more errors of course.
  11. I don't think she's trying to send a list of emails. I think she is trying to send one email but to a different address depending on the option selected in the form. So something like this would set the $to_add variable to the required email address: switch( $_POST['dropdown'] ) { case "choice 1": $to_add = "email@email.com"; break; case "choice two": $to_add = "email2@email.com"; break; } This: case "choice 1": ...is used when this option in the form is selected: <option value='choice 1'>Boating</option> ...Notice the option value and the value of $_POST['dropdown'] Btw. just dropping this code into your script won't work, there are one or two semi-obvious things to change. The two posters in here can post links to the PHP mail function all day long but it isn't going to help with this problem.
  12. ...and I was elaborating on it. I don't think he understood though as he then commented on something to do with sessions. I just made it clearer. Where's the problem in that? Apologies. Thanks for pointing it out. Christian obviously missed that too.
  13. Check if 'Magic Quotes' are turned on in PHP and also check for any 'addslashes' function use within your code. If Magic Quotes are on then all HTTP request data (e.g. $_POST) will automatically be escaped. If you're using addslashes() then additional escaping is being done there too. The above two methods will actually add the backslashes when storing in the database, unlike the mysql_real_escape_string() method, so I'm guessing you're doing one of those things (hence the backslash you are seeing in the DB). Ensure to just use mysql_real_escape_string() and no other methods of escaping.
  14. I think somebody just needs to point out that... md5('$password') ...is obviously not what he wanted to do. I don't think he did it for any reason and I don't think the discussion in this post will actually help him. I think pointing out that the above line of code is very different to any of these will help: md5($password) md5('{$password}') md5("$password") In other words a variable can't be placed inside single quotes. It must be double quotes or enclosed by curly brackets. I understand not giving him the answer straight away and it helps to find the answer yourself, but in this case I think you all toyed with him a little too much.
×
×
  • 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.