• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

trigger an event by visit a webpage

 
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I'm not sure where this fits best, but that's something that bothers me for quite some time now. As I don't have any experience about setting up an application server or have a servlet deployed I'm looking for quite some easy way.
What I want to accomplish sounds simple:
- a user enters an e-mail-address
- a simple php script generates a unique ID and sends an e-mail for verification to the user
- the user clicks on the link and opens the validation page
- the webpage verifies the token and triggers some external event
My issue is the very last step: How to trigger the external event when a user browse to the page? I came up with things like exec() or send another mail to an internal mail account another process listens for via imap idle, or even call something like fsockopen, but all things I came up with either are not recommended due to exploitable security risks or just require some heavy resources not suitable to be used by many users at the same time.

So, does someone has experience in this topic? May I need to provide some more information what I actually want to use this for? Is setting up a full blown application server a good way have it sit idle for the most time hogging system resources? Is there a "good" way to maybe do this with php or other tricks a simple lamp server provides?
I'm open to any advice or questions.
 
Saloon Keeper
Posts: 23263
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It really depends on what the "external event" is. Computers don't execute events, they use events to execute program code. Somewhere there has to be a program that needs to do something when then event triggers.
 
Matthew Bendford
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, the flow is this:
- a new player joins the game server
- the backend checks wether the user has joined before (by a unique id)
- if the user didn't join before a popup is displayed to ask for an e-mail-address
- after input and click a button the e-mail-address is send to the backend, checked if it's valid (by some DNS tricks), generates an ID to be stored in a database and an e-mail is send out
- the user has to check the inbox and click the link
- when the page is loaded the webserver sets a flag in the database (by php as one possibility) - and then the script triggers a callback to the java backend <- this is where I'm stuck
- the java backend sends an event back to the gameserver which results in the game client showing a confirmation and closes the popup

I'm stuck at the second to last step: causing some listener in the java backend to trigger when the webserver loads the php script.
Sure, I could use exec() to call some binary, or use fsockopen to connect to the backend itself, or I even can use mail() while the backend uses imap idle to listen for it, or even google how to setup an application server and send the event back to the game server this way. They're all options possible - but I'm not sure which way to go. To avoid some exploitable open inbox I would avoid the mail approach, using exec() would run some binary with the user the webserver runs, and set up an app server - I'm not sure if that's what I'm looking for as "some simple lines of code". So, maybe using fsockopen() to connect to a control socket opened by the java backend is a possible way.

Any inputs?
 
Saloon Keeper
Posts: 6835
162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the "Java backend"? If it's HTTP-accessible (like a servlet), then the PHP code could call some URL that's serviced by the Java backend. If it's not a servlet environment, it could still open a port and listen on that for TCP message from the PHP code (assuming it's on a network that's separated from the internet at large, as that would open up a number of security issues).
 
Matthew Bendford
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The backend is just some basic java stuff, no servlet container or application server. I do have some very basic http server code which I'm using for my PXE setup, so setting up a reverse proxy in my apache config would also be an option, as this is what I would do to "hide" a servlet container or application server anyway, but a simple control socket is also an option. As I plan to come up with my own protocol for communication between the game extension and the backend anyway I could extend it to be reused for communication between the php and the backend. It's not like I care about some additional latency or fear setting up some additional stuff - but as I'm rather lazy I'm looking for an easy simple way of implementing it.
 
Tim Holloway
Saloon Keeper
Posts: 23263
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Java stuff" apparently means a Java application. Again, loose code doesn't do anything.

Java application code can be fired off in one of 2 ways: 1) Launch an application via PHP's equivalent of Runtime.exec() 2) Post an event or request to a continuously-running Java application.

Option 1 is not high-performance. It takes time to set up and destroy a JVM run environment.

The technical name for Option 2 is "server".

Java RMI is out, if the client is not a Java application (for example, PHP). Likewise, CORBA is dead. Message queue protocol is popular if you like loose coupling, though. Most Java servers these days, however, use HTTP Web Services.

With Web Services, you get high-performance operation and rich supporting infrastructure so you don't have to invent protocols or services from scratch. Assuming you go that route, then, you have 2 options here, as well:

1) A stock webapp server such as Tomcat, jetty, or, if you have extreme needs, a full-stack webapp container. Tomcat or jetty can run stand-alone or as an all-in-one app using Spring Boot,

2) A general application container with web services. For example, Apache ServiceMix.

I'd probably go with the Spring Boot approach if your needs are modest.. On the other hand, if you wanted an all-in-one environment running multiple independent processes with good external interface options, ServiceMix is good for that. I've used it to do things like re-shape incoming email, fetch, summarize and format weather reports and general odds and ends.
 
Matthew Bendford
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim, that reply really got me a push into a possible direction: ActiveMQ
I was looking up Apache ServiceMix, and its wikipedia article mentions ActiveMQ. As I use Apache James as my mail server (actually for a couple of years now - works great) I remembered some message queue (MQ) discussions on its mailing list - and it clicked: As my use case is already heavly event based - why not extend on that and use an event bus - or a message queue for that matter.
I then just looked up ActiveMQ's page - and it already greated me with what I was looking for: some clean info how it can be used by several languages, including java and php. I then looked up how to access activemq from php: STOMP. Looked that up - and after installing the PECL and openssl-devel packages on my server a simple sudo pecl install stomp did the trick. Just added another .ini in /etc/php7/conf.d and a restart of my apache - and it shows up on phpinfo().
I actually already found not just one, but TWO examples explain exactly my use case: use php as the producer and java as the consumer.

I'm currently tinkering around with setting up the activemq borker - but that should be rather easy following the guides I found. Guess THAT's A, maybe THE, route I go, as it fits my overall project so well.

Thanks again Tim for that advice - helped quite a lot.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic