Jump to content

johnsmith153

Members
  • Posts

    709
  • Joined

  • Last visited

Posts posted by johnsmith153

  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. 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.

  8. 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.

  9. 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.

  10. 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.

  11. johnsmith: You might want to read the thread a bit closer the next time, Jessica has already pointed that out.

    ...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?

     

    Curly braces make no difference. Variables are not interpolated within single quotes . Full stop.

    Apologies. Thanks for pointing it out. Christian obviously missed that too.

  12. 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.

  13. 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.

  14. "You're not very smart." Remove the word not, and it's a pretty nice statement as well.

     

    No, remove the word 'not' and your statement means the opposite. Remove the word 'hell' from the question in this topic and it means the same thing. You're removing a word to make a sentence mean the opposite, it's a poor example.

  15. Basically, you are right that nobody uses it, or nobody codes in it if they have the choice, but of course as teynon pointed out some people have no choice and CodeIgniter have ensured they still support it for that reason.

     

    Of course Jessica doesn't always respond in such an unhelpful way. I see you were only asking a question.

  16. I thought it would be worth mentioning that I think the look of the site is pretty good.

     

    I'm no designer at all (I'm actually rubbish), but looks-wise on my 27" iMac it looks ok. The font isn't great, and I'll explain below, but I would say you have good potential. The guys above don't comment on the design, but I doubt they would say that it's as bad as the code.

     

    The fonts don't show up for me. You have used different fonts but haven't specified them in your CSS. To me the entire site uses the Times New Roman font because I don't have the ones you specified installed. Look at http://css-tricks.com/snippets/css/using-font-face/ for advice. Also, you would be better specifying a list of fallback fonts, so do this instead of just listing one:

     

     
    font-family:Arial, Helvetica, Verdana;
    

    ...that way your browser will use the first font in the list that it supports.

     

    Obviously as the above guys have mentioned it isn't coded great, but you'll definitely get there. You seem to have the right attitude too.

     

    I think time does matter in the long run and I would say something like this site should take about 8-15 hours for an expert. I started learning programming 4-5 years ago and I'm 50 times quicker (literally) now than when I started. Also, as you progress you'll keep snippets of code that you can re-use (e.g. a basic HTML layout which you'll use every time you start a new project).

     

    Personally I would start with a 3 page website, follow Ignace's advice (code structure) and if you ever find yourself cutting and pasting chunks of code then you're probably not doing it right.

     

    Keep at it though and good luck!

  17. I do agree with Jessica's part about everybody being volunteers and I'm guessing the adverts are just there to cover the bills. Then you can ignore what feedback you like and do as you wish.

     

    I did suggest four things to improve. Jessica seems to think I didn't but KevinM1 (after double checking my post) managed to see them.

     

    About the respectful attitude of the experts. KevinM1 says this "has merit", so there must be some truth in it.

     

    you criticized all of the staff based on one comment by one of the nicest people here

    My criticism of the staff had nothing to do with one comment from anybody. Which comment was that? I think you are getting defensive and seeing things that are not there.

     

    I don't really understand Philip's response about conversation. The forum can still promote conversation rather than quick-Q&A answers by having a quicker, more modern method of doing so. You don't need to stick to the same forum style as 20 years ago to maintain 'conversation'. It doesn't make sense. Fair point not wanting people to leech off the site, but that doesn't mean you shouldn't change the methods you use.

     

    Jessica asks why am I here. Other than this topic I've made 2 posts this year, so I'm not really here at all. I used to be, my post count shows medium usage.

     

    KevinM1 asks about my solutions to the listed problems and I don't have them. I gave feedback that can either be listened to or ignored, but it will need better people than me to work out the solutions. I just responded to a post as to the reduced activity on the site. Of course it would be better to have detailed solutions, but if I had them I would be running my own help forum.

     

    I do think some people have gotten a little defensive though. Nobody likes feedback, but there are better ways to respond when someone gives it. I mean at least one person has agreed to some of 3 out of 4 of my points:

     

     

    Mobile support? KevinM1 agrees a little bit + Philip agrees

    Respectful attitude of experts? KevinM1 says this "has merit"

    Nice modern site design? Philip and KevinM1 agree.

     

    ...so maybe my feedback was genuine and worth giving. Only Jessica seems to have gotten a little too defensive.

  18. *Shrugs* You don't have to be here, if you don't like it.

    It's not as if you're paying anything, after all.

    It was feedback. And what if I click on an advert or start using that service?

     

    Surely feedback should be listened to so that more people come to the site and click on more adverts. That's business, and that's online marketing.

     

    PHP Freaks should look after its customers. Businesses need to listen to their customers. A comment like this is not listening to one of the site's customers. And I am aware that you are also a customer of the site, but with that 'Guru' badge you have it also makes you a representative of the company. If I had a company representative respond to a customer like this, I would not be impressed.

     

    Customers can be annoying, but you can't turn them away.

     

     

    So, what do you suggest we do to improve?

    The four things I mentioned.

  19. To be honest though, what's 'excellent' about PHP Freaks? In the modern world you have to have something special.

     

    Quick, modern methods of communication? Forums in this style are old hack.

     

    Mobile use? Brilliant if it was 1995.

     

    Respectful attitude of experts? No.

     

    Nice modern site design? Average.

     

    It might be my imagination, but back in the day there was also more conversation on forums. Times have changed and it's almost exclusively Q&A now, where forums have been left in the dust by specialist Q&A-centric sites like StackOverflow and its siblings.

    Salathe mentions conversation, but I can't think of one method where conversation can be slower than it is on PHP Freaks. Maybe 'back-in-the-day' there was more conversation, but just like back in the day people waited 10 seconds for a web page to load, they won't converse on a site like this because conversation is too slow on here - hence why you are seeing Q&A-only communication.

     

    What does PHP Freaks do that is excellent? Nothing unfortunately. It ranks well in Google when you ask "PHP help", but that's about it.

  20. This Monkuar bloke is as weird as hell, but I don't think you'll really grow the site much by using Twitter unless you really put some effort in. If it's just trq pointing out everyone's mistakes every now and then it's not going to do much for you. Many will benefit from Twitter, but I don't see how a very established forum as this will do with just one or two tweets a day by whoever fancies it at the time.

     

    If it's for the fun of it then go for it.

     

    Btw. trq your framework site is shot to shit. Broken links everywhere. It's a right mess.

  21. Roughly how long would it take PHP to perform 4 x is_file() actions?

     

    I have the exact path to the files and all four checks are in the same folder. All files are very small in file size.

     

    I'm sure many people will say, "it depends", but I'm looking for a rough guide.

     

    Are we taking 10ms, 100ms, 250ms, a second, 10 minutes - just roughly?

     

    This will help me decide if to re-write my script so as not to perform the checks and use a different method. Currently this is done on every page request.

     

    Thanks

×
×
  • 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.