Tagged: PHP Toggle Comment Threads | Keyboard Shortcuts

  • DerFichtl 8:24 pm on December 13, 2012 Permalink
    Tags: PHP, , wrench   

    Wrench – The new HTML5 Websocket Class Hero for PHP 

    Wrench is an up-to-date websocket server implementation in php that works with current chrome and firefox versions. The library has no external dependencies, just php 5.3 is required. Some code says more than thousand words …

    A simple server looks like …

     
    #!/usr/bin/env php
    <?php
     
    require(__DIR__ . '/lib/SplClassLoader.php');
     
    $classLoader = new SplClassLoader('Wrench', __DIR__ . '/lib');
    $classLoader->register();
     
    $server = new \Wrench\Server('ws://0.0.0.0:8080/', array(
        'allowed_origins' => array('bohuco.net'),
    ));
     
    $server->registerApplication('echo', new \Wrench\Application\EchoApplication());
    $server->run();

    It’s important to bind the Socket on IP 0.0.0.0 … i first tried it with 127.0.0.1 then the socket is not reachable from external network. If you have a firewall like on Amazon EC2 you must configure it so, that the port (eg.: 8080) is open.

    The actual application …

    … is separated into another class/namespace … here is an example of a simple EchoApplication that echos the received message back:

     
    namespace Wrench\Application;
     
    use Wrench\Application\Application;
    use Wrench\Application\NamedApplication;
     
    class EchoApplication extends Application {
        public function onData($data, $client) {
     
            $client->send($data);
     
        }
    }

    The javascript part would look like this …

    The last part (/echo) of the websocket address is the application name, this name must be registered in server.php with the registerApplication-method (see above).

     
    if ("WebSocket" in window) {
        ws = new WebSocket("ws://46.51.177.248:8080/echo");
     
        ws.onopen = function() {
            ws.send('INIT');
        };
     
        ws.onmessage = function(evt) {
            console.log(evt.data);
        };
     
        ws.onclose = function(evt) {
        	ws.send('MESSAGE');
        };
     
        ws.onerror = function(evt) { }
     
    } else {
    	alert("WebSocket NOT supported by your Browser!");
    }

    More infos and documentation about Wrench:





     
  • DerFichtl 7:31 am on March 24, 2011 Permalink
    Tags: , , PHP   

    Nebel des Grauens – PHPFog 

    Man will ja in diesen Tagen fast nicht von Gau oder Super-Gau sprechen aber der Herr Lucas Calson, Gründer und Inhaber von PHPFog, wird die Ereignisse der letzten Tage sicher so bezeichnen …

    More …

     
  • DerFichtl 1:10 pm on February 12, 2011 Permalink
    Tags: oauth, PHP,   

    OAuth mit PHP am Beispiel der Twitter API 

    Auf den ersten Blick ist OAuth eine scheißkomplizierte Sache, aber mit dieser kurzen Anleitung und dem Zend Framework wird es plötzlich ganz einfach …

    More …

     
    • Philipp 8:41 pm on March 14, 2011 Permalink | Reply

      Hallo,
      Erstmal vielen Dank für das tolle Tutorial.
      Allerdings scheitere ich bereits am Anfang daran, da ich nicht weiß welche bzw. woher ich die dateien aus dem Zend Framework einbinden muss.
      Ich habe mir das Packet runtergeladen, jedoch finde ich dort eine vielzahl an dateien und ordner etc.
      Könntest du mir vl. sagen welche dateien ich da genau benötige?
      In dem Tutorial steht nämlich nichts dergleichen.

      Würde mich über eine möglichst rasche Antwort sehr freuen!

      Vielen Dank
      Lg,
      Philipp

    • DerFichtl 10:03 pm on March 15, 2011 Permalink | Reply

      man kann zend framework hinspeichern wo man will … im script wird dann mit set_include_path der pfad für die includes gesetzt, beispiel wenn du zend framework unter /var/www/yourpage/lib kopierst dann kannst du mit set_include_path(get_include_path().’:/var/www/yourpage/lib’) den include pfad richtig setzen und mit require_once(‘Zend/Oauth/Consumer.php’); die erforderliche Datei inkludieren … also einfach immer die Unterstriche des Klassennamen durch Slash ersetzen dann ist man meistens schon richtig dran.

      sorry … das ich nicht so schnell mitm antworten war

  • DerFichtl 11:11 pm on February 8, 2011 Permalink
    Tags: , , mongodb, , , PHP   

    PHP in der Cloud: cloudControl aus Deutschland bietet PaaS für PHP 

    Wer eine Webseite betreibt oder gar eine Webapplikation muss sich unweigerlich um Hosting und Server Administration kümmern. Dabei gibt es mittlerweile unendlich viele Möglichkeiten … aber jetzt kommt noch eine dazu: Platform as a Service (PaaS)

    Keine Hardware Investitionen, nie wieder Server administrieren oder Sicherheitspatches einspielen müssen, das System skaliert automatisch und das Deploy wird einfacher: Das klingt doch alles wunderbar und das alles bietet SaaS!

    Platform as a Service (PaaS) gibt es seit einigen Jahren für Java (Google AppEngine) oder für .NET (Microsoft Azure) aber für PHP sieht es derzeit noch etwas mau aus. Diese Lücke möchte jetzt cloudControl aus Potsdam schließen …

    More …

     
  • DerFichtl 8:53 am on February 8, 2011 Permalink
    Tags: cli, PHP,   

    PHP Commandline Script in Farbe 

    Bei PHP Gangster hab ich soeben eine kleine Klasse entdeckt mit der CLI Scripte farbige Ausgaben machen können …

    Usage:

     
    $color = new Color();
    $color->set('red');
     
    echo "red textn";
     
    $color->reset(); 
    $color->echoString("red text on bluen", 'red_u', 'blue');
     
  • DerFichtl 10:08 am on January 31, 2011 Permalink
    Tags: chat, example, , , PHP,   

    PHP5 WebSocket Example – A Simple Chat 

    The classic example for websockets is a chat. This chat example has only 200 lines of code (excl. the Websocket class), is really easy to understand and customizable.

    More …

     
  • DerFichtl 2:05 pm on January 16, 2011 Permalink
    Tags: aod, aop, , oop, PHP,   

    Der Erklärbär: Aspect-Oriented Programming mit PHP – Teil 1 – Signal Slot 

    Wiedermal was Neues!? Wiedermal wird die (Web-)Programmierer-Welt auf den Kopf gestellt!? Objektorientiert ist gelber Schnee von Vorgestern, Design-Patterns verwendet heute schon deine Oma fürs Putzen … und jetzt kommt: TaTaaaa! AOP – Aspect Oriented Programming.

    Der Erklärbär erklärt’s! (er versucht es zumindest)

    More …

     
  • DerFichtl 9:17 am on January 14, 2011 Permalink
    Tags: , PHP, , , ,   

    New Google Ranking Checker with Locale-Support 

    A new release of the Google Ranking Checker Class is available now. The new version 1.2.0 is released under a Creative Commons license (by-sa 3.0) and supports locale settings for language and country.

    More …

     
    • Soren 6:54 am on January 20, 2011 Permalink | Reply

      Hi there

      Love the script – Although, I cant get it to work properly… For some keywords it’s ok, but for others it just dont return a result…

      I.e. I have a site called notebooktoshiba.net – I know for a fact that it is currently on position 13 on Google. The script turns up a blank for both “notebook toshiba” and for “notebooktoshiba” – Even “notebooktoshiba.net” gives a blank which should be a given 1st place position on Google. I have the same results for many other sites… What gives?

      I’ve set the locale to “$rankingChecker->setLocale(‘us’, ‘en’);”

      Good work btw ;) Would love to make this work and not jump on a Google scraper…

    • Google Search Rank Checker 4:20 pm on May 25, 2011 Permalink | Reply

      You can use Google search rank checker to check your rankings

    • Google Search Rank Checker 5:19 pm on May 25, 2011 Permalink | Reply

      You can use Google search rank checker to check your rankings

    • Zabbath 8:06 am on August 17, 2011 Permalink | Reply

      I just want to know how to modify your script become multi Ses, so I can chek rank using Google, yahoo and bing using your existing code

    • Zabbath 8:06 am on August 17, 2011 Permalink | Reply

      I just want to know how to modify your script become multi Ses, so I can chek rank using Google, yahoo and bing using your existing code

    • Roger Tschallener 2:49 pm on August 27, 2011 Permalink | Reply

      Ich habe eine kleine Anpassung in der Class vorgenommen, da diese ab dem zweiten Keyword des Arrays bei mir etwas gezickt hat.

      Folgender Bereich habe ich VOR das “foreach($keywords as $keyword) {” verschoben:
      if (! empty($this->country)) {
      $this->country = ‘&gl=’.$this->country;
      }

      Darfst du gerne für ein Update übernehmen ;)

    • Roger 2:49 pm on August 27, 2011 Permalink | Reply

      Ich habe eine kleine Anpassung in der Class vorgenommen, da diese ab dem zweiten Keyword des Arrays bei mir etwas gezickt hat.

      Folgender Bereich habe ich VOR das “foreach($keywords as $keyword) {” verschoben:
      if (! empty($this->country)) {
      $this->country = ‘&gl=’.$this->country;
      }

      Darfst du gerne für ein Update übernehmen ;)

    • Arthur J 11:15 pm on February 2, 2012 Permalink | Reply

      Does anyone know what’s the daily limit on querying Google?

    • Arthur J 11:15 pm on February 2, 2012 Permalink | Reply

      Does anyone know what’s the daily limit on querying Google?

    • Vmukul111 5:24 am on February 11, 2012 Permalink | Reply

      Thanks for the nice code!
      But I could not make it work properly. It always shows the same result unaffecting by locale settings.

      And Can I use your API in my code?
      I could not get one from the link given by you

    • Vmukul111 5:24 am on February 11, 2012 Permalink | Reply

      Thanks for the nice code!
      But I could not make it work properly. It always shows the same result unaffecting by locale settings.

      And Can I use your API in my code?
      I could not get one from the link given by you

    • Msathesh 6:25 am on March 29, 2012 Permalink | Reply

      Your script is accurately displaying the rankings but when I run it on my localhost, it’s getting me the rankings wrongly more often. I simply, do not understand why it’s display different results for same script. The only difference is API key. Which makes no sense to me. Do you know why? Thanks for the script though.

    • Msathesh 6:25 am on March 29, 2012 Permalink | Reply

      Your script is accurately displaying the rankings but when I run it on my localhost, it’s getting me the rankings wrongly more often. I simply, do not understand why it’s display different results for same script. The only difference is API key. Which makes no sense to me. Do you know why? Thanks for the script though.

    • stevo 5:02 pm on April 8, 2012 Permalink | Reply

      Hey there,
      I tried the script on my server and while it does return results, they are different from those shown in the Bohuco Labs example (which are actually correct in my case). In both cases I use de/de for lang/country. Any idea why the script shows different results?
      Cheers,
      Stefan

    • stevo 5:02 pm on April 8, 2012 Permalink | Reply

      Hey there,
      I tried the script on my server and while it does return results, they are different from those shown in the Bohuco Labs example (which are actually correct in my case). In both cases I use de/de for lang/country. Any idea why the script shows different results?
      Cheers,
      Stefan

    • Arthur J 11:13 pm on February 2, 2012 Permalink | Reply

      try ‘en’,'us’

  • DerFichtl 11:40 pm on December 1, 2010 Permalink
    Tags: , PHP,   

    PHP Websocket Class new Version 

    Auf Anfrage einiger Leser habe ich jetzt die Klasse kommentiert und Informationen zur Lizenz hinzugefügt. An der Funktionalität hat sich nichts geändert. Die aktuelle Version 1.0.5 ist unter folgender URL zu finden: http://bohuco.net/labs/php-websocket-class/lib/WebSocketServer1.0.5.php.txt

    More …

     
  • DerFichtl 4:31 pm on October 24, 2010 Permalink
    Tags: PHP, Posts,   

    WordPress Quicky: Query Posts by Custom Meta Field 

    If you have already added a custom meta field to your wordpress posts with add_meta_box you probably want to query such posts in your template. You can do that with query_posts(), it supports the meta_key and meta_value attributes.

     
    query_posts($query_string.'&meta_key=onStartpage&meta_value=1');
     
  • DerFichtl 6:10 pm on October 16, 2010 Permalink
    Tags: , PHP, profile, , , user,   

    WordPress Quicky: Add User Profile Fields 

    If you want add fields to the wordpress user profile then two hooks are important for you.
    More …

     
  • DerFichtl 8:52 am on September 24, 2010 Permalink
    Tags: , , PHP, , Shortcode, ,   

    WordPress Quicky: Use the [Shortcode] API 

    Another quicktipp for wordpress plugin developers. With the shortcode API you can easily provide additional commands for wordpress authors …

    More …

     
  • DerFichtl 9:35 am on September 23, 2010 Permalink
    Tags: , PHP, ,   

    WordPress Quicky: Exclude Categories 

    Another quicktipp for wordpress theme developers.

    If you want to exclude one or more categories from a page (startpage, category-page), you can call the query_posts function with negative category-ids …

    <?php query_posts($query_string . '&cat=-1,-2,-3'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <!-- POST -->
    <?php endwhile; endif; ?>
     
  • DerFichtl 9:45 am on September 22, 2010 Permalink
    Tags: , PHP, , ,   

    WordPress Quicky: Register Sidebar Widget with 3.0 

    Another quicktipp for wordpress plugin developers. Registering a sidebar widget can end with a fatal error if you use the code from the wordpress documentation …

    More …

     
    • Jamy Hudsk 12:17 pm on February 20, 2011 Permalink | Reply

      Thanks, little less info though, you should visit http://wordpressfunctions.com/global/sidebar-global/register-a-new-sidebar.html if you want to know more.

    • Hubert Pic 10:57 pm on March 18, 2012 Permalink | Reply

      Where can i write this code? and what is the “MyWidgetClass” ? I haven’t create a widget and i have this problem … can you help me ?

      (sorry i’m french, and my englsih is so poor …)

    • Nicolas Bouliane 2:00 am on November 25, 2010 Permalink | Reply

      Why is that? I have the same problem (which you have solved), but I’d love to understand what I’m doing

    • DerFichtl 8:59 am on November 25, 2010 Permalink | Reply

      I really don’t know, it seems that the add_action needs to work with the result of register_widget() and not with the widget classname itself. very irrational but …

    • Hubert Pic 10:57 pm on March 18, 2012 Permalink | Reply

      Where can i write this code? and what is the “MyWidgetClass” ? I haven’t create a widget and i have this problem … can you help me ?

      (sorry i’m french, and my englsih is so poor …)

  • DerFichtl 7:42 pm on September 11, 2010 Permalink
    Tags: , , compiler, , , , performance, PHP   

    Use Google Closure Compiler Local with PHP 

    In “Google Closure Compiler with PHP” i described how you can use the compiler online via http. Now i will show how you do it local on your server with the java command line application …

    More …

     
    • Panik 11:07 am on January 12, 2012 Permalink | Reply

      in windows how to do that… i am using xampp and java is installed on C:Program FilesJavajdk1.6.0_18bin

    • Panik 11:07 am on January 12, 2012 Permalink | Reply

      in windows how to do that… i am using xampp and java is installed on C:Program FilesJavajdk1.6.0_18bin

    • Panik 11:07 am on January 12, 2012 Permalink | Reply

      in windows how to do that… i am using xampp and java is installed on C:Program FilesJavajdk1.6.0_18bin

  • DerFichtl 4:10 pm on July 22, 2010 Permalink
    Tags: , , PHP, , ,   

    PHP WebSocket Server – The Handshake 

    WebSockets are the new cool boys in town, but the specs are in a very early state and so it’s hard to keep up to date with the different browser implementations …

    More …

     
    • the future 10:48 am on February 25, 2011 Permalink | Reply

      Thanks so much. I was having some real problems with my handshake.
      :)

    • :D 2:17 pm on December 27, 2012 Permalink | Reply

      my parkinson is still anmnnnciokalpw wj15455f32d

  • DerFichtl 7:51 pm on July 15, 2010 Permalink
    Tags: , , PHP, , ,   

    Google Ranking Checker Class in PHP 

    Check out the new version 1.2.0 of the class! It supports locale settings and is released under a creative commons license.

    New Google Ranking Checker »

    The only goal for an SEO is a good or very good google ranking. To ensure this you have to monitor your rankings and compare it to the positions of your competitors. With the Google AJAX Search API and my little PHP Class you can easy build a Google Ranking Checker …

    The class needs an Google API key for the AJAX Search API (get it here) … it’s just one field and a click and you can start. You can check multiple keywords for multiple domains or urls, just pass this two arrays to the check() method.

    More …

     
    • Bill 9:13 pm on July 18, 2010 Permalink | Reply

      This is nice article learned new things from this site.thanks for sharing

    • Indiana web design 9:54 pm on July 20, 2010 Permalink | Reply

      How do you post this when designing a website? Do you have the Html file?

    • GXKevin 4:26 pm on July 23, 2010 Permalink | Reply

      Nice post! ;-)

      Flying Tech

    • Soren Beck Jensen 6:30 pm on July 26, 2010 Permalink | Reply

      The demo does not work?

    • DerFichtl 9:37 am on July 27, 2010 Permalink | Reply

      thanks for info, bug fixed, now it works again …

    • Travis L 7:25 pm on July 29, 2010 Permalink | Reply

      Demo still doesn’t seem to work.

    • DerFichtl 8:55 am on July 30, 2010 Permalink | Reply

      @Travis Demo works! What do you want to check?

    • Ash 12:34 am on October 19, 2010 Permalink | Reply

      HI,

      This is very useful. Have you licensed this as GPL or MIT etc. Meaning may I use this in my own projects, for clients etc

      • DerFichtl 4:29 pm on October 19, 2010 Permalink | Reply

        hi, thanks for concern, the class has no license it is just free to use and modify for everyone. maybe when i have time i choose a gpl or lgpl license for it …

    • JC 12:49 pm on October 26, 2010 Permalink | Reply

      hi,

      can you show us how we can invoke this script in html?

    • CJA 5:02 pm on November 11, 2010 Permalink | Reply

      I checked out the test script and its not working. I tried a few keywords and came up with no results then i tried the most obvious keyword ‘Google’ and its coming up as 9th position? it should be #1 position.

      • DerFichtl 5:58 pm on November 11, 2010 Permalink | Reply

        Thanks for comment, i have checked the code and it works fine … but: my class is using the german language version and austria as country so google.at is on first position.

        you can easily change that in the class … and maybe i will add this feature to the online demo … when i have time …

    • CJA 5:27 am on November 12, 2010 Permalink | Reply

      you’re absolutely right… i was thinking about that on my way home from work. If the server the script is located on is somewhere else the results will be different. i’ll have to play with your script.

      thanks for the quick feedback :)

    • Ruben Sedano 11:51 pm on December 14, 2010 Permalink | Reply

      but its not very accuracy because i prove with keyword ‘deportes’ and domain ‘clarin.com’ and not results!!! (-) :S

    • Wes 4:38 am on January 14, 2011 Permalink | Reply

      Hey DerFichtl,
      The new version works great! I see a call to RankingChecker.php. Do you have a link to the code in that file somewhere?

      I tried copying the code above to create a RankingChecker.php file to use with the new version, however I get this error:

      Fatal error: Call to undefined method RankingChecker::setLocale() in /home/wadmin/public_html/index.php on line 17

      Thank you, I really appreciate it.

      • DerFichtl 9:28 am on January 14, 2011 Permalink | Reply

        Dear Wes!
        Thanks for using the ranking checker, you can download the new version here.

    • Dreis 9:09 pm on January 14, 2011 Permalink | Reply

      Tnx for this! Awsome & handy script! if you had a donate button I would donate.

    • DerFichtl 11:41 pm on January 17, 2011 Permalink | Reply

      Thanks, DerFichtl!

    • buy generic Keflex 6:33 pm on March 3, 2011 Permalink | Reply

      The Zune concentrates on being a Portable Media Player. Not a web browser. Not a game machine. Maybe in the future it’ll do even better in those areas, but for now it’s a fantastic way to organize and listen to your music and videos, and is without peer in that regard. The iPod’s strengths are its web browsing and apps. If those sound more compelling, perhaps it is your best choice.

    • Waiver Form 5:18 pm on March 5, 2012 Permalink | Reply

      Great Post

    • Waiver Form 5:18 pm on March 5, 2012 Permalink | Reply

      Great Post

  • DerFichtl 8:07 pm on July 11, 2010 Permalink
    Tags: , , PHP,   

    HTML5 WebSockets Example 

    HTML5 WebSockets makes it possible to open a persistent connection to a server within a web-browser via javascript.

    More …

     
    • zcorpan 9:58 am on July 13, 2010 Permalink | Reply

      Firefox can’t open the connection for the same reason Chrome 6 dev can’t open the connection. You have implemented version -75 of the protocol (which Safari 5 and Chrome 5 use), while Firefox and Chrome 6 dev support version -76.

    • DerFichtl 2:37 pm on July 14, 2010 Permalink | Reply

      Thanks zcorpan for your advice … i have recoded my class, now it works with the new Firefox 4 Beta too.

    • deekobraz 9:15 pm on July 16, 2010 Permalink | Reply

      it was very interesting to read.
      I want to quote your post in my blog. It can?
      And you et an account on Twitter?

    • skybinary 2:18 pm on July 26, 2010 Permalink | Reply

      Hey, nice introduction to websockets thanks :)

      I have successfully implemented some examples but they only work from localhost.
      How can i tell apache/php to allow socket connections beyond localhost?

    • jsnoob 10:07 pm on July 28, 2010 Permalink | Reply

      I don’t understand the need for the eval:
      [ eval('var data = ' + msg.data + ';'); ]

      why can’t you just do a real var data = msg.data?

    • DerFichtl 10:23 pm on July 28, 2010 Permalink | Reply

      msg.data contains JSON as string … with eval i convert it to a real javascript object

    • deltaLeo 5:21 pm on September 13, 2010 Permalink | Reply

      Hi skybinary,

      Please ensure that the socket is not just listening for localhost calls.
      e.g., let’s say you are working with port 8181. Then if you type within a terminal ‘netstat -an | grep LISTEN’ and
      you see something like this ’127.0.0.1:8181′ that’s the root of your problem.
      So if you want to permit any incoming connection you should do something like this:
      $webSocket = new WebSocketServer(“0.0.0.0″, 8181, ‘process’);

    • David 5:21 pm on October 13, 2010 Permalink | Reply

      opening two windows with the example doesn’t seem to work.
      The first Window works but the second one not.
      Is it required and possible to set any parameter for the concerned window?

    • David 5:32 pm on October 13, 2010 Permalink | Reply

      After reloading both Browser-Windows it works and I get both cursers shown while the active one is correctly changeable while the other one is passive.
      In a list on the pic the IPs (surely the same) and the cursors are shown.

      Question is:
      1) how are the windows divided by the script
      2) why both windows had to be reloaded and why in the beginning just reloading the 2nd window didn’t show any cursor?

    • DerFichtl 7:10 am on October 14, 2010 Permalink | Reply

      Hi David, which browser (+ version) do you use? If you try with one chrome-window and one chrome inkognito window it should work … or two different browsers.

    • Ldup 8:57 pm on November 14, 2010 Permalink | Reply

      Hello, very thanks you for this! work!
      But i’m too trying PHP WebSocket(http://code.google.com/p/phpwebsocket/) simple example(Chat) but don’t work and i’m get error: Error: INVALID_STATE_ERR: DOM Exception 11
      And status is: WebSocket – status 0

      Maybe know how to fix this ? :-)

      Thanks for this and Good Luck!

    • DerFichtl 12:39 am on November 15, 2010 Permalink | Reply

      Thanks Ldup for your question. I have nothing to do with this project, but i can see that the maintainer is working on the project and he usually answers questions very quick.

    • Yves 8:07 pm on December 17, 2010 Permalink | Reply

      Hi, i have a problem with a scripts that is almost the same as yours. The eval function of the very first message received from the server gives me an Unexpected token ILLEGAL error. But all the other messages after the first one work great. When I read the first message with a console.log(msg.data) there is absolutely nothing strange in this message. Is there something special with the first message sent by the server?

    • cyberbobjr 7:56 pm on January 7, 2011 Permalink | Reply

      Hi,
      i have the same problem as Yves : the first message sent by the server raise always a onerror event on the client, the others messages works fine after… really strange… (chrome version 8.0.552.224)
      Thank you

    • DerFichtl 1:54 pm on January 12, 2011 Permalink | Reply

      Thanks for the comments, i can reproduce the problem and a quickfix is to wrap the eval in a try/catch block. i will look into the problem later, there seems to be a “hidden” char in the response …

    • Macs 12:00 pm on January 20, 2011 Permalink | Reply

      Do you plan to ad “wss” feature?
      this is the only option working for me behind firewall, simple “ws” fail to connect

    • adailton 6:42 pm on January 23, 2011 Permalink | Reply

      an error is occurring on the server can not answer the socket.

      php_exif.dll disabled the dll file that was giving error zend parameter in the library.

      I am using windows xp and windowdows 7 the same error.

      I’m from Brazil my net is networked to another pc

      image the error : http://img218.imageshack.us/i/imagemyj.gif/

    • adailton 6:48 pm on January 25, 2011 Permalink | Reply

      solve the problems agora ta All ok

      thanks for posting can clear my doubts valew old ^ ^

    • adailton 6:21 pm on February 26, 2011 Permalink | Reply

      thanks for posting this beautiful work.
      is being dealt a new server database that connects with
      javascript
      his name is jwebsocket a very good api
      to be compatible with Internet Explorer 6,7,8,9.

      http://jwebsocket.org/

    • DigitalLife 12:41 pm on March 6, 2011 Permalink | Reply

      How does this work? From the little I know about php the script gets called each time a browser opens an page. I understand that the server.php calls run so it doesn’t return like simple php scripts, but why aren’t there server instances for every user calling this script? Is it that the “require_once” makes only the first call of the script work and the other silently fail so there is only one server object? I don’t understand why there are not many WebSocketServer objects with each having only 1 client.
      (Sorry for my bad english, I’m out of training)

      • DerFichtl 9:57 pm on March 15, 2011 Permalink | Reply

        that is not a”typical” php-script which is opened in the browser via http … its a command line script, you can run it for example under linux oder mac osx via “php -q server.php” (if php is installed on the computer) … in this script is a endless-loop, so it runs until it is stopped with Crtl-C … hope that helps :)

    • Edska 3:58 pm on March 11, 2011 Permalink | Reply

      I have problem with this function – private function wrap($msg=”") { return chr(0).$msg.chr(255); }

      I get all info and at the end is this char – ÿ which is chr(255).
      Therefore at the client side I get error – “Invalid char”. If I remove “chr(255)” char “ÿ” is removed, but client side doesn’t work either.

    • Roy 6:59 pm on March 16, 2011 Permalink | Reply

      Hey, i’m tryng to get this to work.
      It still doesnt, and the reason is that crappy ‘hidden character’ that prevents json to be effectively interpreted, thus not appearing in the reply itself.
      here is the discovery:
      http://stackoverflow.com/questions/4880273/character-in-front-of-websocket-message
      But not the solution.I’m still looking for a good one to implement, or a way to get rid of that piece.

    • Roy 7:30 pm on March 16, 2011 Permalink | Reply

      Found a solution: by js, just use the replace function of javascript example, assume msg is the string returned by websocket.message function

      msg = $.parseJSON(msg.data.replace(”, ”));

      or, without jquery:

      msg = JSON.parse(msg.data.replace(”, ”));

      Hope someone will find this helpful to someone.

    • Roy 7:32 pm on March 16, 2011 Permalink | Reply

      Sorry, but the ascii code got interpreted.
      Between the first ” in the code, insert
      0
      without the space between, it will work, giving back your Json content.

    • elennaro 9:39 pm on April 9, 2011 Permalink | Reply

      Fixed memory leak on message quantity:

      Class WebsocketChatMessage {

      ….
      // Added destructor
      public function __destruct() {
      echo “menya stiraut ” . $this->text . “n”;
      unset($this->text);
      unset($this->username);
      unset($this->timestamp);
      }
      // End of added destructor

      ….

      }

      and in

      Class WebsocketChat {


      //added message limit
      private $maxmessage = 10;
      //End of changes in variables

      ….
      if ($msg->action == ‘chat’) {
      $text = filter_var($msg->text, FILTER_SANITIZE_STRING);
      $lastMessage = new WebsocketChatMessage($user->data['username'], $text . ” memory state ” . memory_get_usage(), time());

      $user->data['message'][] = $this->messages[] = &$lastMessage;

      //Begin of cleaning Checking if messages is too much

      if (count($this->messages) > $this->maxmessage) {
      //Cleaning old messages
      array_splice($this->messages, 0, 1);
      array_splice($user->data['message'], 0, 1);
      }
      //End of Cleaning
      }
      }
      }

      now the memory usage is clean and correct the script will live!

    • elennaro 9:42 pm on April 9, 2011 Permalink | Reply

      now who can help me with wss?
      i mean SSL for web stocket workaround.

    • Sanjeev 12:18 pm on May 25, 2011 Permalink | Reply

      I got ‘StartListening: Unable to bind socket – Address already in use.’ error when php -q server.php command execute in terminal.So web socket is not working.

      Please give me direction how can i test web socket properly working or not.

      Thank You

    • Digitalpassion 8:02 am on October 14, 2011 Permalink | Reply

      How much better is this than Ajax JSON callbacks?

    • Digitalpassion 8:02 am on October 14, 2011 Permalink | Reply

      How much better is this than Ajax JSON callbacks?

    • Fili Wiese 2:20 pm on November 1, 2011 Permalink | Reply

      Could you please update the code to support the new hybi-10 draft?

    • Fili Wiese 2:20 pm on November 1, 2011 Permalink | Reply

      Could you please update the code to support the new hybi-10 draft?

    • Arturs Birzgals 10:02 am on November 15, 2011 Permalink | Reply

      function hybi_decode($data){
      $bytes = $data;
      $data_length = “”;
      $mask = “”;
      $coded_data = “” ;
      $decoded_data = “”;
      $data_length = $bytes[1] & 127;
      if($data_length === 126){
      $mask = substr($bytes, 4, 8);
      $coded_data = substr($bytes, 8);
      }else if($data_length === 127){
      $mask = substr($bytes, 10, 14);
      $coded_data = substr($bytes, 14);
      }else{
      $mask = substr($bytes, 2, 6);
      $coded_data = substr($bytes, 6);
      }
      for($i=0;$i<strlen($coded_data);$i++){
      $decoded_data .= $coded_data[$i] ^ $mask[$i%4];
      }
      return $decoded_data;
      }

      function hybi_encode($data)
      {
      $frame = Array();
      $encoded = "";
      $frame[0] = 0×81;
      $data_length = strlen($data); if($data_length > 8;
      $frame[3] = $data_length & 0xFF;
      } for($i=0;$i<sizeof($frame);$i++){
      $encoded .= chr($frame[$i]);
      } $encoded .= $data;
      return $encoded;
      }

    • Arturs Birzgals 10:02 am on November 15, 2011 Permalink | Reply

      function hybi_decode($data){
      $bytes = $data;
      $data_length = “”;
      $mask = “”;
      $coded_data = “” ;
      $decoded_data = “”;
      $data_length = $bytes[1] & 127;
      if($data_length === 126){
      $mask = substr($bytes, 4, 8);
      $coded_data = substr($bytes, 8);
      }else if($data_length === 127){
      $mask = substr($bytes, 10, 14);
      $coded_data = substr($bytes, 14);
      }else{
      $mask = substr($bytes, 2, 6);
      $coded_data = substr($bytes, 6);
      }
      for($i=0;$i<strlen($coded_data);$i++){
      $decoded_data .= $coded_data[$i] ^ $mask[$i%4];
      }
      return $decoded_data;
      }

      function hybi_encode($data)
      {
      $frame = Array();
      $encoded = "";
      $frame[0] = 0×81;
      $data_length = strlen($data); if($data_length > 8;
      $frame[3] = $data_length & 0xFF;
      } for($i=0;$i<sizeof($frame);$i++){
      $encoded .= chr($frame[$i]);
      } $encoded .= $data;
      return $encoded;
      }

    • Paromatt 7:36 pm on March 22, 2012 Permalink | Reply

      Hi
      Please anyone who knows post how to get the “New URL for Example” working.
      I love to see working things before troubleshooting it on my pc later.

      I love websockets!
      matt

    • Paromatt 7:36 pm on March 22, 2012 Permalink | Reply

      Hi
      Please anyone who knows post how to get the “New URL for Example” working.
      I love to see working things before troubleshooting it on my pc later.

      I love websockets!
      matt

    • Elbriga 12:31 am on January 27, 2013 Permalink | Reply

      source code not showing

  • DerFichtl 12:49 am on February 18, 2010 Permalink
    Tags: email, PHP   

    E-Mail Links wirksam schützen 

    Einige einfache Methoden wie man E-Mail Links schützen kann. Aber die richtig guten Ideen sind dann in einem Kommentar-Link zu finden.
    More …

     
  • DerFichtl 2:04 am on November 7, 2009 Permalink
    Tags: , , curl, , , PHP   

    Google Closure Compiler with PHP 

    Today Google released their new Closure Compiler, you can use it to optimize and minify your javascripts.

    More …

     
  • DerFichtl 9:31 pm on June 30, 2009 Permalink
    Tags: garbage collector, , PHP   

    PHP 5.3 fertig! 

    Die neue PHP Version ist nun endgültig fertig und freigegeben. Zu den neuen Funktionen gehören Closures, Funktionsobjekte und Lambda-Funktionen, die native MySQL Library, namespaces und late static binding. Aber für mich am wichtigsten sind die Performance-Verbesserungen, PHP 5.3 wird ca. 1,5x so schnell sein wie 5.2 und durch den neuen Garbage Collector deutlich weniger Speicher verbrauchen.

     
  • DerFichtl 8:43 pm on June 14, 2009 Permalink
    Tags: PHP, ,   

    Einstieg: Zend_Service_Twitter 

    Einen eigenen Twitter-Client schreiben geht mit der richtigen Library ganz schnell. Im aktuellen Zend Framework ist die Komponente Zend_Service_Twitter enthalten die sehr einfach zu verwenden ist.

    Zuerst mal anmelden und die Daten des angemeldeten Benutzers ausgeben:

     
    require_once 'Zend/Service/Twitter.php';
     
    $twitter = new Zend_Service_Twitter($username, $password);
    if ($user = $twitter->account->verifyCredentials()) {
    	foreach($user as $k => $v) {
    		echo "$k: $v<br />";
    	}
    }

    Die Leute denen man folgt inkl. Bild und Link ausgeben:

     
    foreach($twitter->user->friends() as $user) {
    	printf('<div class="l"><a href="http://twitter.com/%s"><img width="48" height="48" src="%s" /></a></div>',
    		$user->screen_name, $user->profile_image_url);	
    }

    Und so einfach kann man seine eigenen Replies ausgeben lassen:

     
    foreach($twitter->status->replies() as $message) {
    	echo "<div>";
    	printf('<a href="http://twitter.com/%s"><img width="48" height="48" src="%s" /></a><p>%s %s</p>',
    		$message->user->screen_name, $message->user->profile_image_url, $message->text, $message->created_at);
    	echo "</div>";
    }

    Für so ziemlich alles gibt es bereits die Methoden die man nur mehr aufrufen muss und dann SimpleXML-Objekte zurückbekommt. Ein etwas größeres Beispiel könnt ihr unter folgenden URL finden: http://bohuco.net/dev/twitter.php
    Natürlich werden die Twitter-Zugangsdaten nicht mitgespeichert! (siehe Quelltext)

     
  • DerFichtl 10:25 am on January 23, 2009 Permalink
    Tags: loc, PHP, stats, subversion, svn   

    LOC and Author Stats with Subversion 

    Very, very simple author and LOC statistic with Subversion blame function and PHP. So you can see how many lines are already in the repository and which user coded it.

    [sourcecode language="php"]

    // include only this folders
    $dirs[] = '/var/www/portal/application';
    $dirs[] = '/var/www/portal/html/scripts/k2';
    $dirs[] = '/var/www/portal/html/scripts/service';
    $dirs[] = '/var/www/portal/html/styles';

    // function from php.net
    function listFiles( $from = '.') {
    if(! is_dir($from))
    return false;

    $files = array();
    $dirs = array( $from);
    while( NULL !== ($dir = array_pop( $dirs))) {
    if( $dh = opendir($dir)) {
    while( false !== ($file = readdir($dh))) {
    if( $file == '.' || $file == '..')
    continue;

    $path = $dir . '/' . $file;
    if( ! is_dir($path)) {
    $ext = substr($file, strrpos($file, '.')+1);
    // include file extensions
    if (in_array($ext, array('html','php','phtml','inc','js','css'))) {
    $files[] = $path;
    }
    } else {
    // exclude subdirs
    if (! in_array($file, array('fckeditor'))) {
    $dirs[] = $path;
    }
    }
    }
    closedir($dh);
    }
    }
    return $files;
    }

    $files = array();
    foreach($dirs as $dir) {
    $files = array_merge($files, listFiles($dir));
    }
    $stats = array();

    foreach($files as $file) {
    $tmpFile = '/tmp/blame.tmp';
    exec("svn --non-interactive --username myuser --password mypass blame $file > $tmpFile”, $o, $r);
    $output = file($tmpFile);

    foreach($output as $line) {
    $parts = split(‘[ ]‘, trim($line));
    $author = $parts[1];
    if (! isset($stats[$author])) {
    $stats[$author] = 0;
    }
    $stats[$author]++;
    }
    }

    var_dump($stats);
    var_dump(count($files));
    [/sourcecode]

     
  • DerFichtl 9:32 pm on November 26, 2008 Permalink
    Tags: , PHP, ,   

    Zend Framework 1.7 released 

    Wohhh … da geht was weiter … schon wieder ein neues Release von Zend Framework. Mit Twitter und jQuery Support. Da hab ich schon wieder was zu tun die nächsten Abende.

    Außerdem gibt’s einen neuen Performance-Guide in der Doku.

     
  • DerFichtl 8:26 am on November 4, 2008 Permalink
    Tags: , permutation, PHP, power set   

    PHP Arrays: “power set” and all permutations 

    Found in the online-version of PHP Cookbook from O’Reilly.

    “Power set” = combinations of all or some elements

    On one of our development servers (php 5.2.0) we had a problem with the original version of this function, it looked like an endless loop till memory limit exceeded. Here is the rewritten version from Srdjan:

    [sourcecode language='php']
    public function powerSet($array) {
    $results = array(array());
    foreach ($array as $j => $element) {
    $num = count($results);
    for($i=0; $i<$num; $i++) {
    array_push($results, array_merge(array($element), $results[$i]));
    }
    }
    return $results;
    }
    [/sourcecode]

    All permutations

    [sourcecode language='php']
    function pc_permute($items, $perms = array( )) {
    if (empty($items)) {
    print join(‘ ‘, $perms) . “n”;
    } else {
    for ($i = count($items) – 1; $i >= 0; –$i) {
    $newitems = $items;
    $newperms = $perms;
    list($foo) = array_splice($newitems, $i, 1);
    array_unshift($newperms, $foo);
    pc_permute($newitems, $newperms);
    }
    }
    }
    [/sourcecode]

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel