Communicate between shared hosted web site and Windows service - php

What is the best way to communicate between a shared hosted PHP site (on GoDaddy) and a Windows service on computer at another site? I would like to build a site that will allow a customer to schedule tasks on their server, and then look at logs of those tasks that have run. The problem is getting the scheduling information from the web site to the server, and then pulling log information from the server back to my web site. I will have access to the server to install a service (not sure what language would be best to build the service).
I’ve thought of two options. I wonder if either of these two options makes sense or if a third option would be better.
Option 1 - Sockets:
My PHP code would use fsockopen and fputs
My Windows service would open a socket and receive the text.
The problem I see is potential firewall difficulties. Also, the two would have to open sockets at the same time.
Option 2 – FTP:
The windows service would periodically (once a minute or so) open an FTP connection to my GoDaddy site and place a file and also check to see if there is a file to pull down.
Any thoughts would be appreciated.
Thanks.

Related

How to Make a Web Application Work Online, and Offline

I recently built a web application for my company, but the client needed the application to work both offline and online, depending on the availability of internet connection.
Anyways, I'm looking for a way to allow my application to run offline and online. The following technologies are used: PHP, MySQL, jQuery, HTML, and CSS.
Clients could be using that app without internet connection; if there is internet connection the app will automatically move to using the hosting server.
This is either trivial or insanely difficult, depending on a few things:
Does your client have an internal network it can use?
Can that internal network be accessed from the outside?
How many users will your application have?
Are they all on the same network?
On the trivial end of the scale, you can host the entire application locally on your client's network, that can also be accessed from outside, if there is an internet connection. But if there isn't as long as you're on the internal network, the service continues.
On the insanely difficult end, you can build your service so that each browser stores enough information on the machine to allow the user to continue to use the service even if internet connection drops. And then when the connection resumes, the service syncs any updates to the browser.
But this all depends on the answers to those questions.

Access files in remote computer with php

I need to create an application using php which is hosted in a server and need to communicate with a csv file located in clients local machine. Is there any way we could do this ? How can I connect to a remote csv file ? Is this possible ?
Server machine accessing a csv file directly from a client machine is not a good idea. It's a security threat indeed. Consider you are navigating some website and it's server is able to access your computer's file system!!!
There are various alternatives to achieve this, some of these might be:
Make the user upload csv files to server in order to make it
available to the server application
If the client and server are in the same network, then share the
folder on client machine to make it accessible from the server
etc... I would have preferred the first option as mentioned above.
As #AnthonyB mentioned in comment under your question, server can't directly call client, and that is true. Server is called "server" as it serves requests from the client.
To be able to give away files to remote requests, your client needs its own server application, like Apache HTTPD for example.
In case if you need continuously request client's server to collect files with your PHP server, what you are looking for called "worker". One of AWS tools called Elastic Beanstalk offers possibility to choose a server or a worker application during start up wizard for PHP. It is pretty straight forward and easy to use.
Please note, that your client must have dedicated IP address or use Dynamic DNS approach by pushing its IP to a DB (or directly to a server) where worker will take it from.
If you don't need dedicated worker, you can configure CRON JOB to send requests to clients server applications.
IMHO, all that scenario worth it only if you are building corporate grade application. In most cases (and if you do REALLY need to collect files from clients) you have to install Apache + PHP server on the client side and make this guys to wait for request from YOUR remote php server. Without it, you can not get files from clients computers via browser without user input interactions. At least legally :)

Web Hosting on Amazon AWS (PHP + MySQL)

I am totally confused on how to host a Dynamic website created using PHP and MySQL in Amazon Cloud.
I went through Amazon S3 and I hosted a static website there!
Then I tried Amazon EC2 and I learned some aspects about the concept of VPC. I thought that the dynamic websites are hosting in Amazon Cloud using EC2. I followed some steps and they taught me how to launch a website using Drupal (But, I didn't want that !! )
No other tutorials on EC2 to deploy my web application was not found.
Then I found AWS Elastic Beanstalk, I uploaded a simple PHP document and I can see that deployed successfully.
But Still, I am not satisfied. Because, I don't know which is the correct way to deploy my PHP application.
So can anyone direct me on Deploying a PHP MySQL Application in AWS ?
Depends on your needs. Elastic Beanstalk might be a good option for many apps, but I chose EC2 for my app's backend (using PHP, MySQL and S3 for storage).
Quick steps to get you up and running:
Log into the AWS Mangement Console and start a new EC instance (Windows server 2012 R2 Base > t2.micro should be good enough for a start!)
At step "6. Configure Security Group", add Rules for at least HTTP, HTTPS and RDP (so you can connnect via Remote Desktop)
Connect to your new instance via Remote Desktop and install a decent browser (Enable File Downloads in IE's Security Settings and download Chrome or Firefox)
Open the Windows Firewall and add rules for the same ports you opened in the Security Group of your Instance in the AWS Management Console. (Right-click on “Inbound Rules”, then select “New Rule…”)
Download and install XAMPP (I put it in C:\xampp)
Open the XAMPP Control panel and install Apache and MySQL as services (so they will start automatically when your instance launches); make sure everything is started up.
Now put your files in C:\xampp\htdocs\ and you're ready to go!
Bonus Steps:
Set up Filezilla FTP Server (and open the required ports in both the instance's security group and the Windows Firewall) so you can upload/download files without having to go through Remote Desktop.
Get an Elastic IP and assign it to your instance, so it's IP address will never change.
Get an SSL certificate so you can use HTTPS
The answer depends on the load that you are expecting and the resources you have to handle all the administration tasks.
If you expect heavy or variable loads, there are many reasons why not to deploy a production PHP + MySQL application on a EC2.
Here are some of the benefits of deploying to Elastic Beanstalk instead of a manual configured EC2:
You get version control of each deployment.
You can scale up or down automatically if you need more/less instances to handle new load.
You get a load-balancer in front of your EC2s instances with a bunch of out-of-the-box "recommended" configurations.
Regarding MySQL, if you go for an Amazon RDS instance you can handle replication, monitorization and automatic backups with pretty low effort. A lot of the configurations you would need to tweak are now available through parameter-groups.
On the other hand, if you want to have full control of everything that is going on on your server (that means you have time to monitor, backup and do maintenance tasks, which is not my case :), or if you do not plan to have much traffic, or if you want the less expensive option, you should go with a low cost EC2 instance.
In my experience, (after 2 years of working on AWS with 10 production applications, I'm kind of a regular AWS user) pretty much every customization or change I needed on both RDS and EBS I was able to tweak it and get it working, so I'm pretty satisfied with choosing the EBS+RDS option.
Below are two links i found which are helpful to Create and Update an Application with AWS Elastic Beanstalk
https://aws.amazon.com/getting-started/tutorials/launch-an-app/
https://aws.amazon.com/getting-started/tutorials/update-an-app/

File sending from browser to a server which is not a web server

I want to send a file from my browser to a server which is not the server on which the site is hosted.The problem is the another server is not a web server.
Is it programmatically possible to send a file to different server without the involvement of host server? I do not want copy of the file I am uploading on my hosting server.
Sorry for not being clear on the first go. I hope this makes sense.
Note: I have the IP address of server. Implementation has to be done in a secure way.
Create a signed application to handle the upload.
One of the fundamental rules of browser sandboxing is that you don't let the browser communicate to a server other than the one which provided the website. This has been a rule for quite some time, and is done for security reasons.
The only way I know of to bypass this restriction is to use a signed application. This is possible in several languages including at least Flash and Java. Once you've signed your application with an authoritative source, then you can specify that your application is known to communicate with a third-party server and should be trusted to do so. The process of doing this will be different depending on the technology you choose.
The server to which you are sending the file needs to allow some sort of protocol in order to accept the file. You do not specify what that is, but these languages should be more than sufficient to implement whatever you need.
given that you have the necessary authentication of the secondary server you can
i'll explain using ftp, but there can be other socket related ways
1) upload the file to your server as usual, using $_FILE
2) use the ftp class in php to transfer the file to the remote host
Thanks all for valuable suggestions. I am opting for bit weird way but it seems the only feasible solution considering the current requirements of the project.
I am planning to install lite version of web server and php on the external server which can accept uploaded files through browser.
Our team has worked out this is the best solution we can consider as of now.
Thanks again to all for their suggestions.
This is done all the time with Firefox plugins, (youtube etc.). Does it have to be driven from your page source ? How stealthily do you want to do this ?
The other server should use a common protocol, SSH or ftp or NFS or CIFS.
In any case the user is going to have to agree with the plugin or the applet or a third party service (think punkbuster) running in the background.
BF4 runs in a browser window via a plugin and routinely sends data to servers other than the game server.

Bypass tcp/ip communication to service located on same server

I'm working on a project that is located on 2 domains within same server:
1. DataSource system, which provides data for main app
2. Main app, providing the data for front-end app.
App 1 needs to work on seperate domain, as it's data source for more applications. I'm trying to find some way to boost communication performance. Simple call from app 2 to app 1 takes approximately 0.3-0.4s.
Is there anyway to force server to bypass TCP/IP communication and call service directly from localhost?
Both applications are written in PHP with Zend Framework. The server is IIS. Both applications are based on SOAP solutions.
Would appreciate any tips. Will provide additional information if needed.
Thank you in advance for any help.
You have a misunderstanding here. If you call services from localhost (i.e. via Zend_HTTP_Client), this means you are using the tcp/ip and http layers here. Everything works via sockets, no matter if localhost or external ip address.
If the other application needs to be accessible "from the outside" (no integration possible) you can imho only speed up by using a faster webserver (e.g. nginx), turning off modules in your webserver that you don't need or writing your own socket server, dismissing a whole lot of the processing apache and nginx do. http://devzone.zend.com/209/writing-socket-servers-in-php may help you with your first steps.

Categories