poddys Posted July 23, 2010 Share Posted July 23, 2010 I am fairly new to PHP/Javascript, so please bear with me... We have a system that is written in PHP, but for some employees that work in China, where connection to the internet is not always good, there is a cut down offline version of the system that they use on their laptops, uploading to the main system when they can. We don't have a way to update this offline system right now, and I would like to try to include a check when a user logs in to the online system, to see if the offline system is installed on their pc (test for a local file/folder), and to give them the option of downloading updates. With PHP being server side, I am not sure what the best way to do this is, and I am all Googled out trying to find an answer. Any suggestions as to which way to proceed would be much appreciated. Thanks Tony Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/ Share on other sites More sharing options...
JonnoTheDev Posted July 23, 2010 Share Posted July 23, 2010 There is no way that this can be achieved using PHP. You would require some kind of ActiveX control or Java Applet with Java installed on the user PC's test for a local file/folder If websites could access the contents of a users pc can you imagine the consequences. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090142 Share on other sites More sharing options...
poddys Posted July 23, 2010 Author Share Posted July 23, 2010 Agreed, the security aspect could be a BIG issue. Could the server program execute a PHP program on the PC using a "localhost" url? That way the user could click on a link on the "online" system, which would call an install program, which is already on the offline/local system, and that would download files from the server and install them. Is that feasible, without having to learn all about Active X controls and Java? Appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090178 Share on other sites More sharing options...
JonnoTheDev Posted July 23, 2010 Share Posted July 23, 2010 Could the server program execute a PHP program on the PC using a "localhost" url? No. 'localhost' is a loopback address to 127.0.0.1 which is itself (the server where the script executes). There is no bridge between server & pc. Take for example a website that uses Java. If the Java runtime is not installed on a users pc the website usually displays a message with a link to download the Java runtime. Once installed it is embedded into the web browser so the website is able to obtain information from the users pc such as the version of Java they are running, etc. So, the communication from server to pc application is via the web browser, not directly into the pc filesystem. This is the same with ActiveX components. The issue with this sort of communication over the web is that hackers find holes in ActiveX and web browsers to cause damage to pcs. Any ActiveX components will now display warning messages in modern browsers. It is also likely that any firewall software or antivirus will block the sort of communication that you require. I am not an expert on this subject. Hopefully someone else may pick up where I have left off. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090229 Share on other sites More sharing options...
DavidAM Posted July 23, 2010 Share Posted July 23, 2010 We don't have a way to update this offline system right now, and I would like to try to include a check when a user logs in to the online system, to see if the offline system is installed on their pc (test for a local file/folder), and to give them the option of downloading updates. If you provide an install link on the main system, you could set a cookie indicating the version that they last downloaded. Then check that cookie at login to see if it is older than the current version and suggest they install the latest and greatest. Of course, the existance of the cookie will only indicate that they downloaded it. If the install fails or is cancelled, it would be wrong. Or, if the install is an executable running on the client's computer, you can have the last step of the install be to open a specific page with a specific parameter and have that page set the cookie indicating a successful install of the version. If the offline version is running PHP, you could have it use curl to request a specific page from the main site which would return the current version level available. Then it could suggest that the user visit the update page to download the latest. Off course, since it's the offline version, the curl request might fail if there is no internet connection. Of course if it succeeds, the offline version could tell the user that the internet is available and suggest they use the main site (with a link to open it). Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090241 Share on other sites More sharing options...
poddys Posted July 23, 2010 Author Share Posted July 23, 2010 Thanks Neil and David. The cookie idea would work, since if the cookie doesn't exist or gets deleted, it would imply that the version of the offline system is the initial one, minus any updates. I would prefer if I could retrieve something from a file on the offline system, but no biggie. The offline system is also in PHP. It's a cut down version of the online system, for use when the internet is not available. I assume that I can't execute a program from the offline system by calling the program from the online one? If I understand your response correctly, there is no way to reference localhost from the server? I could however execute a PHP program on the server from a link on the offline system though right? Problem is, they only use the offline system when there is no internet connection. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090323 Share on other sites More sharing options...
gizmola Posted July 23, 2010 Share Posted July 23, 2010 You can do what you're talking about using files and javascript. Simply have a manifest file of some sort in the localhost version. You need a script that returns the latest offline version number. The online version also needs this script. Then it's simply a matter in the online version of a javascript routine that runs, that calls both scripts and compares the version strings. If there is a newer version, you start the process to download the newer files. Probably the best way to handle that is to have the updates in zip files and you then have the client download the zip update, and unzip it into the proper location. Mambo/Joomla has this capability albeit it not in an automated fashion, for installing modules, and you might also want to look at the serendipity blog, which has an update management repository system called SPARTACUS built into it that will download newer files for plugins and update the server. You can look at code for each to see what they've done. With that said, it sounds like all you really want is to mirror these systems, and there are existing tools like rsync and unison that you should take a serious look at, to see if they could handle your issue for you without having to create your own system. File permissions in regards to php are extremely important to understand obviously, because you could easily lock down a system so that php will not have the required permissions needed to write the updated files where they need to go. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090346 Share on other sites More sharing options...
poddys Posted July 23, 2010 Author Share Posted July 23, 2010 Thanks very much Gizmodo. That does sound like what I want to do. I wish it didn't have to be in Javascript, which I still find very awkward to work with in some ways. I am old school - 30 years writing RPG on IBM Midrange systems, so PHP/Javascript is pretty new to me. The online/offline systems are not complete mirrors, but in theory could be. I want to be able to download new program versions, update the SQL database, and set the version id, so that ought to be possible. Will check things out on Monday back at work. After weeks of searching for ways/techniques, I have already in a matter of hours had some fantastic advice on here. Really appreciate your prompt help. Have a great weekend. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090380 Share on other sites More sharing options...
gizmola Posted July 23, 2010 Share Posted July 23, 2010 Javascript is a necessary evil these days for most people. However there are some great libraries and tools now to help. Most people are using jquery, which can do amazing things for you clientside with much of the complexity hidden from you. Since you need to make some Ajax calls to do what I suggested, I think you'll find it a great help purely for that reason alone. The docs seem really simple and clear to me, so hopefully it will be fairly easy for you to get some quick and productive code together. Also there's a plugin for Firefox called firebug you want to get, that will help you understand what is going on with your ajax calls while you are developing and debugging. The main thing to keep in mind is that your PHP scripts run serverside, so anything you want to do clientside has to be done in javascript or some other clientside technology like activex or flash. In this case jquery ajax calls should be capable of facilitating what you want to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090383 Share on other sites More sharing options...
poddys Posted July 23, 2010 Author Share Posted July 23, 2010 That is extremely useful, thank you so much. Ajax is proving really hard to learn, I guess I will get there eventually. At least I do know HTML! I have been using Firebug, it's great. The site doesn't work 100% in Firefox (yet!), I took it over from someone who left, but I have been using Firebug to do some debugging. One of the problems is that you can't easily debug PHP line by line, so for me at least there is a lot of trial and error to see what is not working when a page will not display. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090396 Share on other sites More sharing options...
gizmola Posted July 23, 2010 Share Posted July 23, 2010 Yeah php debugging can be a challenge. THere actually is debugging support out there, in particular a lot of people successfully use XDebug along with an IDE like the eclipse with PDT or the Zend editor. XDebug is quite useful for a variety of things, so if you can get a development environment setup with the xdebug extenstion enabled you might find it useful. Also, if this is going to be a long term maintenance project for you, it might be helpful to build in your own debugging console. It's fairly easy to do -- you just add a div at the bottom, and create some simple debugging routines that will spit out that data into the debug div. Great for things like spitting out query variables, session variable contents etc. I've turned around more than one floundering project by adding in that type of capability into a complicated system, and allowing myself and the other devs a quick way of seeing what's going on and calling a few simple debug functions. I usually have a config variable that allows me to turn the debugging on and off, so I have it on in the development environment, but it's turned off in production. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090417 Share on other sites More sharing options...
poddys Posted July 24, 2010 Author Share Posted July 24, 2010 That's a good idea, and simple to build in as well, thanks for the tip. I do similar things on the AS400, but working on that platform is so much easier. It's just green screen though! The worst thing is when I make some PHP code changes, and the screen won't display. Then you can't display anything. Just have to go back and comment out lines and keep trying until you find what does work, or what you did wrong. I don't like the "trial and error" method of trying to spot the character out of place etc... Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1090528 Share on other sites More sharing options...
gizmola Posted July 26, 2010 Share Posted July 26, 2010 That's a good idea, and simple to build in as well, thanks for the tip. I do similar things on the AS400, but working on that platform is so much easier. It's just green screen though! The worst thing is when I make some PHP code changes, and the screen won't display. Then you can't display anything. Just have to go back and comment out lines and keep trying until you find what does work, or what you did wrong. I don't like the "trial and error" method of trying to spot the character out of place etc... Yeah that is challenging, and something we are pretty used to working around in the webdev world. You definately want to make sure you know where your error logs are, that they are turned on and assuming you have a development site, that you have all the error configuration turned up for php, so that you see runtime errors displayed. If of course you just have an error that is breaking the html rendering, that's harder to debug, but that doesn't happen to much to me. I really advise against people using hosts where they don't have shell access, because you need to be able to jump in and tail the error logs (http and/or php) when you're in active development. Needless to say, you need to have looked into your php.ini file and your httpd.conf so it's clear how these things are all setup, and the locations. The good old phpinfo() function is also very helpful at times for finding out the true locations of your webroot, and which config files are being read. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1091407 Share on other sites More sharing options...
poddys Posted July 26, 2010 Author Share Posted July 26, 2010 I don't really know much about the server setup, other than it's an IBM AS400 (iSeries), and we are developing using Websmart, and using Zend. Checking the logs and making sure all the logging is turned on will be my next step I think. Sorry I didn't respond to the thread earlier. I got sidetracked, waylaid, as you do in this busines... Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1091426 Share on other sites More sharing options...
gizmola Posted July 26, 2010 Share Posted July 26, 2010 Haha, cool stuff. Years ago I worked for company that ran its financials on an as/400 and the as/400 guy was always trying to convince me to run a webstack on the as/400. We had lots of sun pizza box servers for the websites. Fun to see someone actually doing that show up here. If we ever have someone with any as400 questions I'm going to point them your way, hehe. Good luck with the project and let us know how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/208651-updating-offline-system-ideas-needed-please/#findComment-1091440 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.