Jump to content

johnny86

Members
  • Posts

    210
  • Joined

  • Last visited

Posts posted by johnny86

  1. Depends on your environment but you should install XDebug extension for your dev environment and enable remote debugging, configure it to netbeans and whenever you're having problems insert brake points in your IDE and start your debug session... That's just one tool, but I've loved it. For AJAX development I'd give a go for FirePHP; a great tool for Firefox

     

    http://www.phpeclipse.com/wiki/Howto/XDebugAndPHPEclipse

    http://www.firephp.org/

     

    Also with crome, use your console to see what data goes on in requests and responses. There are a lot more tools but these are pretty good to start with.

  2. I've given up a lot of thought on directory structures due to my personal project (a framework, what a surprise). I decided to go with full PHP 5.4 so earlier versions would not be supported.

     

    I ended up mapping namespaces to directories which is pretty obvious. That is all the framework itself understands and is as simple as it gets. I see no need for other kind of naming or structure. Developers may off course add their own extended loaders for the autoloader if needed.

     

    The structure under library is as follows (this is just imaginary):

     

    FWNAME means frameworks name so in your case I'd do Proem / Proemi / Proema / Proemt

     

    - /library

          - /FWNAME

                - /Validator

                      - Email.php // Implementation

          - /FWNAMEA

                - /Validator

                      - Something.php // Abstract class which can be extended to do something more complex maybe

          - /FWNAMEI

                - Validator.php // Validator interface which all implementations have to implement. Abstract classes are kind of templates

          - /FWNAMET

                - /Utility

                      - ArrayMethods.php // Trait which have utility methods for arrays

     

     

    So the idea was to just put Implementations, Abstract classes, Interfaces and Traits under different directories in library.. I think it keeps the structure very clear on where everything is and I (or developers) don't need to use some prefixes in classnames or files etc. Every class has it's own namespace so there should not be collisions in class names since Controller\Standard is different from Dispatch\Standard. The namespaces are declared right at the begining of every file.

     

    What are your thoughts on that?

     

    Modify:

    If I'm missing something here please let me know =)

    I think that you can safely bring(use) those classes in(to) a same namespace together because they'll still have their own namespaces and are instantiated using the namespaces. A developer may off course make own aliases to reference them..

  3. Seems like you know the exact entry point of the request since you are talking about a file on your server.

     

    Get the XML content from the request (presumably you just need the request body or some post parameter which holds the content)

     

    Load it with SimpleXMLElement http://www.php.net/SimpleXMLElement

     

    Exctract the data you need with xpath and create some kind of logic on what you will do with each request.

     

    On the other hand, if you're receiving soap requests, you could get to know to PHPs' own SoapServer http://www.php.net/SoapServer or use some wrapper library to handle the requests. For that you basically just need to create a service class which will hold all the actions provided by your API.

  4. Hello,

     

    I'm not so sure how familiar you are with MongoDB but at a first glance I'd structure my mongo documents (or objects) so that I have hosts document and within that I'd have events. Event "documents" inside Host documents. It all comes down to what other needs you may have. But as simple application as you are describing this works great.

     

    I've worked with PHPs MongoDB library and my personal opinion is that it works great and doesn't really need to be wrapped too much. But I sometimes miss things like unified syntax for saving an object into a database.

    - Keep your mongo connections separated (if you have many connections)

    - Keep your mongo database instances separated too in a container, create them when needed

    - Keep collections under your databases so you can initialize new objects (in PHP)

    - One object in PHP = One document in MongoDB Collection

     

    This way when object is saved in PHP (or fetched), the object itself will know what collection it belongs to, collection knows what database to use, and db knows what connection to use.

     

    Here are resources for mongodb and PHP: http://www.mongodb.org/display/DOCS/PHP+Libraries,+Frameworks,+and+Tools - I've looked into them and some of them seems useful enough to use. In my case I decided to wrap my own classes to help me with mongo :)

     

    Just to check something out: http://crodas.org/activemongo.php - This is what I mean. Allthough that library seems very useful I don't like the API of it. But that is the path I'd take.

  5. ALTER DATABASE xxxx CHARACTER SET utf8 COLLATE utf8_danish_ci;

     

    Should get you on utf-8.. Now you do have to make sure that all your files are also utf-8 and you send the proper headers for the browser telling you prefer utf-8.. Remember to define charset at your html head with meta tag.. When you get input, check the content-type header also to make sure the browser is sending utf-8 back. Some browsers won't tell you the type but then you just have to rely on the right behavior. If you're getting wrong charset; use iconv to convert the data to utf-8. You need to know what you're converting and the only way to know it is if the browser tells you what charset it is sending...

     

    All and all that's the basics of making sure you always have the right charset.

  6. What is nasty about getting the defined variables and comparing them? Parsing your file is a lot uglier in my opinion...

     

    I would do something like:

    <?php
    $vars = get_defined_vars();
    include('your_php_file.php');
    $vars_in_your_php_file = array_diff_assoc(get_defined_vars(), $vars);
    

     

    This will have a small issue though. Having the same variable with same name and value already defined before including your vars, the var will not be present in the resulting array.

  7. I would probably take a different approach on the problem at hand. Leveraging the power of node.js http://nodejs.org/

     

    Install node.js on your server. After that create a simple http server with node.js which all your clients will connect to. This webserver would then keep a pool of all open connections (in other words people that are on your site). It would also be responsible for distributing any events that happen in your application to your clients. Create an api method that will only accept connections from localhost (or defined IP addresses with an API key, considering scalability). That API method simply proxies all stuff that it receives (from your PHP scripts) to your clients.

     

    Inside PHP scripts. Create a class that that will send your events to the node.js http server ie $nodeJs->triggerEvent(new CommentEvent(stuff you need here));

     

    Now the nodejs server will loop through your open connections and send the client a json object like { event : "comment", params : { "news_id" : 3232, "comment" : "Hey cool stuff" } } - This goes to your clients browser which has a javascript (could be jquery prototype or whatever js framework you're comfortable with) embbeded that receives this message from your server. Create a library that will modify your UI as you need it to. For this example your JS would try to find a comment box on the users browser -> if it finds one -> see if the comment box is assigned to the "news_id" news -> if it is -> add the comment "Hey cool stuff" to that comment box.

     

    This was very trivial example but you should get the idea. Those examples that you have looked at seem so messy..

     

    In short:

    - Browser has a script that connects to your node.js server. (This script will also receive stuff and you can pass al the received events to your own library)

    - PHP (or other language even) can trigger events by posting to your node.js server (Consider your node.js server as an observer that is notified by subjects and it will then do the stuff that needs to be done on certain events)

    - Node.js just sits there between and propably JSON encodes the stuff coming from PHP (Save time for your PHP scripts, just push the events and the data needed for node.js, and do all the formatting there)

     

    This way you can even narrow the events to be sent to a certain session (user) by just adding a param when you open your client connection. When you open the connection from browser, also send an identifier to node.js which will bind the specific IP address or connection to that ID. This ID should be generated by PHP so that you can refer to it over and over.

  8. It seems like it's intentionally made that way.. But I looked into how Zend_Form builds the elements and subforms internally.. Didn't really get the hang of the logic.. Seems like at some point Zend forgets to add the array to the name of the element.

     

    I was hoping that someone with a wider knowledge of Zend could have answered this question.. If this is unsuccessful I'll report to Zend and see what they say..

  9. Hi everyone,

     

    I came across an annoying bug in Zend Framework and have been trying to find an answer through several forums.

     

    The problem is that when I have a form and add a subform in in and add subform into that form and then add an element into the last subform which belongs to an array; Zend_Form loses one array from the middle.

     

    Demonstration:

    <?php
    $form = new Zend_Form();
    
    $subForm1 = new Zend_Form_SubForm();
    
    $subForm2 = new Zend_Form_SubForm();
    
    $element = new \Zend_Form_Element_Text('textElement');
    $element->setBelongsTo('textThingsInArray');
    
    $subForm2->addElement($element);
    
    $subForm1->addSubForm($subForm2, 'subForm2');
    $form->addSubForm($subForm1, 'subForm1');
    
    echo $form->render();
    // NOT EXPECTED!
    // <input type="text" name="subForm1[subForm2][textElement]" id="subForm1-subForm2-textElement" value="">
    
    // THIS IS EXPECTED
    // <input type="text" name="subForm1[subForm2][textThingsInArray][textElement]" id="subForm1-subForm2-textThingsInArray-textElement" value="">
    ?>
    

     

    How could I overcome this problem? This is making me mad... I couldn't find a patch anywhere for this issue

     

    I know the Zend_Form_SubForm "overrides" the elements belongsTo but it's totally wrong; If elements in the subform belong to an array it doesn't mean that an element could not belong to some array itself and the array would then belong to the subforms belongsto option.

  10. Hi everyone,

     

    I've been trying to find a decent SOAP client library for PHP. The problem with PHPs own SoapClient is that it's very basic and doesn't really have support for different namespaces and headers with namespaces. It doesn't have the option to make custom attributes on soap headers or params. It can't make nested headers with SoapVars or Params and so on. Same goes to Zends SoapClient which is basicly just a wrapper for PHPs SoapClient.

     

    Is there any good client library that could handle all this stuff?

  11. Example:

    $area = $form->createElement('multiCheckbox', 'area_type');
    $area->setLabel('Type of Area:');
    $area->addMultiOption('1', 'Shopping district (individual shops on a street)');
    $area->addMultiOption('2', 'Shopping mall');
    $area->addMultiOption('3', 'Mini-mall');
    $area->addMultiOption('4', 'Airport shop');
    $area->addMultiOption('5', 'Other');
    
    $area->setValue(array('2', '5')); // Selects area 2 and 5
    

  12. I wouldn't go and use definitions.. Here is a good article about localization in PHP:

    http://docstore.mik.ua/orelly/webprog/pcook/ch16_01.htm

     

    It's not by any means too comprehensive.. But there are atleast things I've found useful. Defining your languages to array is a basic easy-approach solution. But if you want performance, use gettext() or the alias _() and manage your language files through your command line or use something like Poedit to make it a little easier. Take a good look at internal php localization; setlocale(), date_default_timezone_set() combined with the right functions ie. time functions are very important to use to provide everyone information in their own national date/time format and weekday names etc etc. Like strftime() will create a date for you according to your locale.

     

    An article to set you up with using gettext: http://onlamp.com/pub/a/php/2002/06/13/php.html

    Poedit site: http://www.poedit.net/

  13. <?php
    
    $data = file_get_contents('file.txt');
    
    if(strpos($data, 'findThis') !== FALSE)
    {
        // found 'findThis'
    }
    else
    {
        // Did not find 'findThis'
    }
    
    ?>
    

     

    I see Maq already posted almost identical code now that I clicked post.. But use !== FALSE because strpos could return 0 if the string found starts at offset 0 and that will result in a false in the if statement and would therefore give wrong result:

     

    if(0 == TRUE) // FALSE

  14. You could try to get better performance by reading only one line into memory at once.

     

    Something like:

    <?php 
    
    $handle = fopen('file.csv', 'r');
    $totalSalary = 0;
    $totalRows = 0;
    
    while(($lineData = fgetcsv($handle)) !== FALSE)
    {
        if($lineData[0] !== NULL)
        {
            $totalRows++;
            $totalSalary += $lineData[indexToSalaryValue];
        }
    }
    
    fclose($handle);
    
    ?>
    

     

    That way you don't have a huge array stored in your memory which I think causes your script to be so seriously slow.

     

    Another thing that could help is to split your file into many files and read those to save some memory.

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