How to set up online directory that two servers can access? - php

I have a very weird, but specific situation. I use XAMPP localhost on my mac, call it server1, and heroku running a php app, call it server2. I need to move a txt file from server1 to server2 (at regular intervals as the txt constantly updates). I cannot use PHP's ftp as heroku doesn't like that. I have no idea how to do this.
I have come up with a plan to somehow get the txt from server1 to an online 'directory' that the app on server2 can access, but I have no idea how to do this, or if this is even possible? Is there a better way to transfer the file? Should I not be using heroku for this in the first place?

Heroku is great for running PHP apps, but it has an ephemeral filesystem. It's not build to upload files and store them on the "server".
(https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem)
If you deploy a new version of your app to Heroku, the uploaded file will be removed. If you don't mind uploading the file again, simply push it to your PHP app running on Heroku using a POST request.
If you want to save it more reliable, think about using a storage service like AWS S3.

Related

php file not accessible at client side when same file uploading on server through FTP

I having bunch of .php files in local & server. Those all files using at client side (mobile app) as web services. But when those file/folder uploading on server via FTP after modified at that time some web service stopped working or misbehaving(returning HTML content in web service response) at client side because of file uploading process going on.
Sometime also facing this issue for single file too when my local network is slow and trying to upload file on server.
I having many live users and getting rarely this issue when file uploading from server side.
Having AWS server and FileZilla using for FTP.
You face a typical problem of non-atomic operations. The solution is to make the operation atomic, that means, change all files at ones.
For this, you have all files in a directory, likely your htdocs directory. Next, you rename this directory to htdocs1 and create a new directory htdocs2. And finally, you create a symbolic link htdocs to point to htdocs1.
Now, you can take all the time it takes to upload all new files to htdocs2. Once you are done, you change the symbolic link to point to htdocs2 rather than htdocs1.
Finally, if you use some PHP accelerator, you might need to reload the webserver (or PHP-FPM) in case you face caching problems.
For the next update of your site, you do the same, just upload into htdocs1 and then change the symbolic link back to it.
So in short:
mv htdocs htdocs1
mkdir htdocs2
ln -sTf htdocs1 htdocs
Just adjust the last command if you want to use the other directory.
In case you do not have shell access, you can also write a PHP script to do that for you, as PHP can also create symbolic links: http://php.net/manual/en/function.symlink.php.

how to download file from heroku with git

How can I download my currently changed file from heroku server?
I built a PHP application that is running on Heroku.
If I use $ git clone git#heroku.com:myappli.git -o heroku then would this upload my original project files from my computer to the Heroku server?
If I use $ heroku git:clone -a myappli then would this download the whole project files to my computer?
How can I download my file (logfilled.txt) from the Heroku server?
Like most PaaS providers, Heroku does not provide a persistent filesystem:
Ephemeral filesystem
Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted.
This means that every time you deploy files that you have created or modified will be lost or reverted to the last committed state. It is probably not a great idea to create your own log files on Heroku.
However, Heroku automaticaly logs anything printed to standard out or standard error:
Writing to your log
Anything written to standard out (stdout) or standard error (stderr) is captured into your logs. This means that you can log from anywhere in your application code with a simple output statement.
Logs may be retrieved using the heroku logs command.
Try using PHP's error_log function to write your logs. If you are using a logging library like Monolog you may have to configure it to output to php://stderr instead of to a file.
Finally, you could write to an arbitrary file like logfilled.txt and make that accessible via HTTP, then download it using a regular web browser, wget, curl, or any other tool. Note that you will almost certainly want to build some authentication around this; using Heroku's logging facility is a much better option.

How to run an php application without installing xampp on client system?

In my application i have to deploy my application on client system.
So is there any way to run my php application without installing xampp...
Because the client should access it as a readymade app without installing anything...
This is the description of my project...
We have to develop an application where the client will have our application he will connect to remote server
Then he will download the data from remote server...
Then he uses that downloaded data using that app
Here my requirement is the user may not have the knowledge of installing the xampp...
So is there any way to run the application in user system just by copying some files
U may suggest me a one click solution (like using installer which will include installation of xampp and copying my data into user system)
I really dont want to use any external software to render no database PHP pages so I did some digging and found that if you run php -S localhost:port in your working directory you basically start a server there.
S is a capital S and not s
I'm a big fan of server2go. I've used it to deploy PHP applications on CD/DVD. It comes with MySQL and is relatively easy to configure. I've even replaced their splash screen with my own so no one knows I'm using it. It's donationware, but I was impressed enough to donate:
server2go-web
With this application, you don't have to install all that other stuff. It's self-contained in this executable and directory.
EDIT: To clarify, server2go does not install anything on the client machine. It runs as an exe only when you specifically want it to. When you click on the .exe file, it launches your PHP application in a browser window, then you can right-click on the server2go icon in the system tray and close it when you're done.
EDIT2: One gotcha: if you want to save data to the MySQL db on the client machine, you'll need to copy serve2go to a directory on the client machine or run it on a writable USB stick. If you run this application off CD/DVD, it will be able to read data from the database, but not write.
The better way is to use PHP Desktop Application. It will allow you to run your PHP Script like a Desktop application and you don't need to install Xampp or any other web server to run.
PHP Desktop Application
After downloading the .Zip file unzips it to any folder that you like. After unzipping, Go to the folder, and there you can see a folder "www". Delete all the files contained in it and move all your php script to it.
Once you moved all your files into it. Run the .Exe file named "PHP desktop-chrome"
It will open your PHP Script really like a Desktop Application.
This script doesn't require any kind of server software like Xampp, Wamp, Etc installed in your PC.
You can either host the php application or install the application into one system as server and call in client system using the ip of the server system like the following
http://**ip address/php file name
If you don't want your client to install anything then you should create Client Server architecture, there is no another way.
PHP Application are not meant to be deployed on multiple clients. It's meant to be deployed on a webserver (your own server with sth. like IIS or XAMPP) so the clients can access it via their browser and doesn't have to install anything more.
If you want to deploy applications on the client pc's i recommened an other programming language like Java or C/C++.
I simply used xampp zip version so i copied my application into htdocs and the whole xampp is given to the customer so he simply running the application eazily without installation.
Make sure you have installed php from https://www.php.net/downloads.php. Once installed add it to path. Lastly type php -S localhost:8000
PHP needs to be installed on the machine it is running at in order to make sure it works. Since the app may grow and may require extension installing, PHP upgrading over time, hosting this on a client machine is not a very easy task in terms of management. You may want to host your project on a server and write a small bash script sending requests to the API.
If, for some reason you cannot host this on a server where your clients would send requests via the bash scripts, then you may want to install only PHP. If it does not need to listen to HTTP requests, then you do not need a server, you can just implement the PHP application and create a bash script so the user will be able to run it from the UI of their operating system.
No, you need some kind of server - Wamp, Xampp, etc.
You can host it online, and then he can just browse it from his PC.

Is possible to connect to Windows Machine via PHP?

I want to write a PHP script that connects to a network PC's C drive: \MAINPC\C$ and then authenticates itself (I provide the username and password) and then iterate over the file in another folder. The iterating part is easy, but I am stuck as to what to use to actually connect to the Windows server or whether or not I would have to use some low-level socket connection?
There is this:
stream wrapper to access Windows shared files
It wraps the smbclient program.
Further discussion in this SO question.
You can mount network shares to device names in windows, or simply mount them to a directory (via smb) on linux.
Then to php it is a simple file operation. You will have to make sure that the share is up tho.
PHP cannot magically access data on another machine.
You need a server on that machine (here the windows PC) that serves the file system you are interested in. Then you can create a php script that accesses the content of the filesystem by using that server.
Actually there are ready-to-use components for that stuff.
Is the webserver on a linux/unix-box?
Are the machines on the same LAN?
http://www.samba.org/samba/docs/man/manpages-3/smbclient.1.html may help you.

Daemon to synchronize local directory with Amazon S3 (AMI using Ubuntu Linux and PHP)

are there any solutions to keep synchronized an AMI's local directory with an S3 bucket?
The idea is to be able to deploy a standard LAMP webapp (and it's user file uploads) without the need to alter the current code.
I can imagine something like a daemon updating "AMI's local directory" <-> "S3'sBucket"
I know this is not a scalable/efficient solution in the long run, but it would provide a quick-n-dirty solution for my current needs (to deploy a webapp in many Amazon's EC2 instances with DB replication).
A better (if not perfect) solution would be if local directory would be somehow 'symbolic' (like symbolic/hard links) and not actually phisically consuming space; but seamlessly accesible from a standar webapp.
Any ideas ?
Thanks !
Apparently this solves my question, I haven't tried it yet, but it looks like what I was looking for.
http://ikorolchuk.blogspot.com/2012/02/mount-amazon-s3-storage-as-local.html

Categories