Xampp + Php Websocket Maximum execution time error - javascript

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?

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.

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

Related

Host Python on server and call from React Expo App

I am working on an app that uses machine learning, and recently run into a problem. I found out that Expo and Python do not really work together.
I thought that a solution would be to host and run my machine learning model (Python) on a server, and then make requests from my JS Expo app, and I thought this would also have the hidden bonus of faster processing compared to just on my laptop.
So, can people confirm whether firstly this is possible (to call python code running on a server, from a JS Expo app) and if so, then provide some recommendations as to where I can host this?
This is for a university project, so I am hoping to find something either free or cheap, thanks.
I thought this would also have the hidden bonus of faster processing compared to just on my laptop.
If you want to do it for free then lowest tier instances on any cloud will have 1 or 2 cores plus 1-2 GB of RAM, it won't be stronger than your local device and it won't have any hardware acceleration, but if you planned to run that on your phone then it might be enough
So, can people confirm whether firstly this is possible (to call python code running on a server, from a JS Expo app)
Short answer yes, but
The way you formulated this question does suggest that you don't know how this communication would work. You would need to
send http request from expo app to some endpoint on your server
implement server code that could accept that request, in your case it's probably best to do that in python(with sth like django or flask)
in your server code execute tensorflow code
if tensorflow code executes quickly you can send results in the response if not you will need to have second endpoint to check results
This is for a university project, so I am hoping to find something either free or cheap, thanks.
for local development you will need to host it locally either way, for university project it should be enough, but if you want to have it on public server you can get free tier or some starting credits on almost any cloud service e.g. digital ocean gives 100$ credit for students
Alternatively you can use tensorflow in react-native app, you just can't do it in python, https://blog.tensorflow.org/2020/02/tensorflowjs-for-react-native-is-here.html?m=1

How to make a Command Line application with WebRTC in Linux?

I have an idea for a side project where i will connect two terminals(clients) using WebRTC and they will share some data with each other(assume a CLI chat app) using Node.js. But wherever i read about WebRTC it always says that it works only in browsers. Like the fact that if a machine does not have a browser that supports WebRTC then it would not work in the machine. Do statements like these mean that WebRTC can only work in the browser. If not then how should i approach making something like this?
The functions i want the application to have :-
1.) It should connect with the peer when i write "node client.js" in the terminal (client.js will be the client script).
2.) The terminals should be able to send each other messages.
3.) No need of the browser.
I've made such applications using WebSockets and i dont intend to use them in this project.
Yea this is possible, and people are doing it today!
Check out ascii it is a command line WebRTC client that does camera capture and encoding. It uses the Golang library pion/webrtc
I am sure it is possible with nodejs as well, but don't know how much work it would be.
Also if you are doing chat only it is even easier! See pion-to-pion really easy example to have two processes communicate via WebRTC.

How to get data from web form into a file on the server [pm2]

So- I have some python scripts running permanently on my VPS and I want to be able to send them data to chew on via a simple web interface.
I do not mind how it gets the data. It seems to me that the simplest is probably to write the data to a file, and the python script automatically reads from this file every X seconds for changes. Then the solution need not involve python in any way.
From reading elsewhere, I believe the simplest solution is a simple php script. The problem here is that I'm running a pm2 server on the VPS. Pm2 does not support php I believe- and I can't install LAMP as this would presumably interfere with pm2.
I've looked into trying to do this with JS but that saves files client side and I need it server side.
I've also looked into cgi (I have zero experience with this) but pm2 doesn't seem to support this either?
Is there some fancy solution using node js?
What is the best way to tackle this problem!?

Can web chatting application using socket.io be built without ssh access or keeping the terminal running?

I have a website written in php. Till now I used setTimeout with ajax to update chats simultaneously but after that didn't work I learnt about socket.io. I need to implement private messaging and I have got some things covered in socket.io but when I ran it on localhost I had to keep the terminal open as long as I wanted to chat.
1. How am I supposed to do that on my server which is Hostinger currently. Is there some terminal I need to run or do I need ssh(shell) access which I don't have at the moment?
2. If there isn't, how would the node script keep running?
3. And since socket uses node, how would the app use node modules? Do they need to be uploaded to the hosting space?
Apart from that, if there is any private messaging and group messaging implementation anyone knows about even other than how it could be done in socket.io it will be very helpful if you could suggest. I need the users to chat among themselves not with me.
Thanks in advance!
You can do this by using node js ,socket.IO and express.js
Link given below can provide you with a rich documentation to reach a solution.
https://socket.io/get-started/chat
For running your application in background you can use PM2 process manager.
For documentation refer below link
http://pm2.keymetrics.io/

Integrate Node.js with Symfony2 or PHP

I'm developing a web application with Symfony2. I need to create a push notifications sysmte (like Facebook). When an user publish something, I need some of another users receive a notification.
I saw that Node.js it's the easiest manner to do this. But, I did some simple examples and all works fine, but I don't know how can I integrate this node.js application with my Symfony2 application, or really with a PHP application.
Anybody can help me?
Thanks in advance!
Please note that you've not given enough details, so I will respond as a front-end developer and not as a mobile developer
Integrating NodeJS and PHP (in general) is not a good way since you need to launch both servers separatly, create the websocket server in JS while your application is in PHP and finally create a request (GET or POST) from your PHP to you JS server. Well, a big mess, so I'll expose my solution here under.
Quick insight for mobile apps. Well, technically, there's no easy way. You can use the Push "protocol" (http://www.wikiwand.com/en/Push_technology) with NotificationPusher (https://github.com/Ph3nol/NotificationPusher). I didn't used it before so I can't help you with it.
In general.
Most of the time when people thinks of Push, long polling will do the trick. For starters it means that the request is made client-side and the server don't send data & close connection until there's new data.
How do you implement this ?!?
Basically, you change the max_execution_time using ini_set or set_time_limit to a very long time for the current script and launch a loop (like a do..while) with a sleep and the check to your data inside. From your Javascript just make an Ajax call, for example with jquery: $.get. Just remember to remove the timeout and stay in asynchronous mode.
The only drawback of this solution is that you will always have a connection opened to your server which will consume a bit more of battery on a mobile device. If you have multiple types of data to receive do not hesitate to merge the calls and publish a type in your response data, since most of the browsers allows only 2 or 3 simultaneous connections to the same server.
I sounds like your describing WebSockets.
Take a look at Socket.io, its a module for node.js.
Also there is a example at GitHub https://github.com/Automattic/socket.io/tree/master/examples/chat
Interesting files for you should be the index.js and the public/main.js.
You can see the example live at http://socket.io/demos/chat/

Categories

Resources