0

its my firsttime using it.
Ok i tried to use websocket ext. but i dont understand it :/
In this article http://www.sanwebe.com/2013/05/chat-using-websocket-php-socket/ i download it, extract it in folder, and i open command prompt execute this

c:\xampp\php\php-cgi.exe -q c:\inetpub\wwwroot\CC2\ws\server.php

I open index.php in 2 browser and connect it. Two browser connected as well. But after 30 second, connection is lost. I looked in cmd, gived this error

C:\Users\traBolic>c:\xampp\php\php-cgi.exe -q C:\inetpub\wwwroot\CC2\ws\server.php
<br />
<b>Fatal error</b>:  Maximum execution time of 30 seconds exceeded in <b>C:\inetpub\wwwroot\CC2\ws\server.php</b> on line <b>28</b><br />

I dont understand it, is that normal? How can i keep connection live in a long time?

traBolics
  • 89
  • 1
  • 3
  • 13

2 Answers2

1

If you're already familiar with PHP and you don't want to move to an entirely new platform (node.js/socket.io), you CAN implement websockets with PHP.

Take a look at the Thruway project, which is a PHP implementation of WAMP (Web Application Messaging Protocol). It simplifies getting websockets working with PHP and provides SubPub and RPC.

I'm one of the developers of Thruway, so if you have any questions or need help getting something working, you can open an issue on github.

If you want to read more about WAMP, here's a good place to get started.

Also, php-cgi is designed to be run by your web server. Check and see if XAMPP has a php-cli.exe or a plain old php.exe and use that instead.

daviddan
  • 416
  • 2
  • 8
  • Ok, if u say that dont need to move nodejs, well i dont. @Dustin's answer set_time_limit ( 0 ) is worked. But this time i have another issue :/ keep live c:\xampp\php\php-cgi.exe -q c:\inetpub\wwwroot\CC2\ws\server.php command after closing command prompt. In linux it can be start as a service. Can i do that in windows? – traBolics Oct 08 '14 at 12:55
  • Ok i solve the problem as start command as a windows services. – traBolics Oct 08 '14 at 14:15
0

You need to set per

<?php set_time_limit ( 0 ); ?>

the maximum execution time of a php to infinite, because php has a default maximum execution time of 30 seconds. You should have a look on Socket.IO which handles Websockets much better than php.

Best regards

Dustin

Edit:

ohh... sorry for not explaining socket.io... Socket.IO is an module for nodejs: Node.JS is the V8 Javascript Engine from Google Chrome for a server. So you can run a server with javascript on command line. Socket.io is as I said a node module. In node JS you can import modules from npm which is an packet manager for node.JS. It provides functionality for bi-directional connections between the client and the server via websockets and fallbacks to long-polling xhr requests. Easiest way to come up with it is just trying it. For example you can try to start this chat app: Chat.

First you need to install node.JS, which should be simple node.JS.

You can start a node.JS server the same way you have already done it with php:

Console:

>node index.js

Now you should be able to use the chat by opening the index.html file.

To answer your question: No, you can not start socket.io with php. And you can neither use xampp to start a nodejs app.

There are a lot of tutorials in the internet right now. Someone has already created a list: Tutorials

Best

Dustin

Community
  • 1
  • 1
Dustin Hoffner
  • 2,025
  • 1
  • 14
  • 15
  • Thanks for help. But im new on php right now. I dont know how to use socket.io. I think socket.io not working with php isnt it? Can u show how can i user socket.io on windows xampp? – traBolics Oct 06 '14 at 15:22
  • Just a clearfy before starting NodeJS. I'm leaving php completely? am i right? – traBolics Oct 07 '14 at 15:32
  • Yes, ... please don't feel forced to use node.js. When you are comfortable with php and don't need more power just use it ;) – Dustin Hoffner Oct 07 '14 at 19:31