Hi, is it possible to run apache and php locally from the app? If so what do I need to do to be able to do that? I have tried searching the forums and google but haven’t got any wiser. There is WSAPI and FastCGI but Im not sure how to use that and package it so it could be run from the app, and Im a total newbie when it comes to using hooks as many documents points out there describe. Never used Luarocks before. But do I really need to go that route or could the php script be executed the same way as calling and externel web server. Or is it possible to just use io.popen or os.execute.in some way to get it to work?
I’ve never heard of an app running Apache or PHP inside of it. It certainly cannot be done with Corona SDK. There would be way too much native side work needed. Apple doesn’t generally permit arbitrary execution of code that wasn’t included in the original submission outside of Javascript.
What you might be able to do though is use Lua sockets, which Corona SDK supports and build your own web server that would listen on port 80 and respond to HTTP requests (GET, POST, etc.), but that would be a lot of work. But you’re not going to likely get any scripting language by Apple, which would nuke a PHP type feature.
Even if you accomplished this, what will be connecting to it? How will you handle DNS to an ever changing IP address? Are you expecting things outside your device to connect to it? What happens when the app is backgrounded or the device is asleep? Are you sure you can safely manage the security of your app? Web servers are a great attack vector for hackers.
Rob
Thanks for the response Rob, I my be seeing this the wrong way but in the last couple of weeks I have been forced to shift my code to php a couple of times because I can do some advanced funktions in php that I have a hard time doing in corona. The reason is not for the app to serve as an server, but php is server side and thats only way I know that php scripts can be utilized locally. The reason I wanted it was basically because php and apache have more folder/ file functions/information then corona sdk has at the moment. But those functions are for most restricted to where apache is installed, but It is one of php:s “streangts” If I’m not misstaken cordova apache is built around the same ide that the app to some extent works as a server and the apps can utilize this be a little more flexible. But I do understand your points about security issues. I was thinking something more along a “sleeping” type that was used only to execute php scripts when needed.
What is it that you’re trying to do?
Right now Im trying to get the amount of available free space on the phone. In php its as easy as:
<?php
$localDirectory = disk_total_space("/");
$localFreeSpace = disk_free_space("/");
echo $localDirectory;
echo " … ";
echo $localFreeSpace;
?>
But I can’t find a way to do this in lua. I think this could be done in java to, not sure.
Corona SDK is not going to provide you a way to do that. We support LFS (http://docs.coronalabs.com/api/library/lfs/index.html) for getting file attributes, directory listings and such. But that won’t gather free space. This is something that would likely be done using Enterprise or CoronaCards so you could call the appropriate device SDK to get the info you need.
Also because the way apps are sandboxed, its unlikely you have access to / anyway.
Rob
Yes, but thats over my pay grade at the moment. And thats exactly why it would be nice to be able to utilize other scripting langues for smaller stuff that don’t need that much code. Wouldn’t the free space info tell me how much space I have to use based on the hole os? Or at least thats how I think the information is given, I haven’t read anywhere that its needs any access to anything else then the sandbox folder for this kinda information.
There is a PHP port for iOS, but it’s a standalone app that you write your PHP directly into. It can’t run like executing code from another app. It’s also $10 per install.
Apache Codova and Zend studios have built a way for PHP programmers to build native apps, but this would not be using Corona SDK, but their system.
If you want to use Corona SDK/Lua, I’m afraid the only option open to you now is Corona Enterprise or CoronaCards. We are working on the Marketplace to allow Enterprise developer’s to build and sell their own plugins. No ETA on it’s availability, but when it comes on line, you could commission an Enterprise developer to build a plugin that would fetch the various native bits of data you need.
Rob
That would be grate Can I ask why simple information like this that is both available on android and iOS isn’t already available in the system getinfo api? Its really just a couple of line of code on both platforms…
Time vs. Benefit.
While it’s not a lot of code to provide that information, by the time you have to write up the specifications, schedule the work, figure out how many Corona SDK uses would actually use the feature vs. things that are more in demand, research each piece of information, code it in both ObjC and Java, decided on common language to bridge the two OS’s (well now 3, we would have to support it for Windows Phone 8 too), then write the actual code (three times), test it and many edge cases, document it, provide sample code, etc., it’s a serious investment in engineering time. How much benefit is that time going to serve?
This is one reason we have http://feedback.coronalabs.com
There you can request features and get the community to voice their opinion through the voting system and comments. You’re more than welcome to request this feature. On the grand scale of things, this is pretty easy, but if only three people want it, yet hundreds want feature XYZ that’s nearly the same engineering effort, we will do XYZ. Not all feature requests are the same. We will do easier requests with fewer votes when very hard requests are going to require considerably more votes.
So feel free to post a request for this information and get people to vote on it.
Rob
You do make a good case Do you know if android and iphone return any error information back to the app when maximum capacity have been reached? Or does it just cancel what ever is going? Ive read lots of posts on the forums about apps being rejected because big files and so forth, but nothing about what actually happens in the os and if it could be caught through a callback.
I would assume that file IO would just fail when full.
As for rejecting apps… It’s not large files specifically, but large files in system.DocumentsDirectory that are downloadable from the Internet. These need to go into system.CachesDirectory. Secondly since system.DocumentsDirectory is automatically backed up to iCloud. Large files eat up a lot of iCloud space and Apple is likely to complain about this if you don’t set the flag that keeps it from being backed up.
Rob
Never thought about iCloud uploads. Thanks for pointing it out.
I’ve never heard of an app running Apache or PHP inside of it. It certainly cannot be done with Corona SDK. There would be way too much native side work needed. Apple doesn’t generally permit arbitrary execution of code that wasn’t included in the original submission outside of Javascript.
What you might be able to do though is use Lua sockets, which Corona SDK supports and build your own web server that would listen on port 80 and respond to HTTP requests (GET, POST, etc.), but that would be a lot of work. But you’re not going to likely get any scripting language by Apple, which would nuke a PHP type feature.
Even if you accomplished this, what will be connecting to it? How will you handle DNS to an ever changing IP address? Are you expecting things outside your device to connect to it? What happens when the app is backgrounded or the device is asleep? Are you sure you can safely manage the security of your app? Web servers are a great attack vector for hackers.
Rob
Thanks for the response Rob, I my be seeing this the wrong way but in the last couple of weeks I have been forced to shift my code to php a couple of times because I can do some advanced funktions in php that I have a hard time doing in corona. The reason is not for the app to serve as an server, but php is server side and thats only way I know that php scripts can be utilized locally. The reason I wanted it was basically because php and apache have more folder/ file functions/information then corona sdk has at the moment. But those functions are for most restricted to where apache is installed, but It is one of php:s “streangts” If I’m not misstaken cordova apache is built around the same ide that the app to some extent works as a server and the apps can utilize this be a little more flexible. But I do understand your points about security issues. I was thinking something more along a “sleeping” type that was used only to execute php scripts when needed.
What is it that you’re trying to do?
Right now Im trying to get the amount of available free space on the phone. In php its as easy as:
<?php
$localDirectory = disk_total_space("/");
$localFreeSpace = disk_free_space("/");
echo $localDirectory;
echo " … ";
echo $localFreeSpace;
?>
But I can’t find a way to do this in lua. I think this could be done in java to, not sure.
Corona SDK is not going to provide you a way to do that. We support LFS (http://docs.coronalabs.com/api/library/lfs/index.html) for getting file attributes, directory listings and such. But that won’t gather free space. This is something that would likely be done using Enterprise or CoronaCards so you could call the appropriate device SDK to get the info you need.
Also because the way apps are sandboxed, its unlikely you have access to / anyway.
Rob
Yes, but thats over my pay grade at the moment. And thats exactly why it would be nice to be able to utilize other scripting langues for smaller stuff that don’t need that much code. Wouldn’t the free space info tell me how much space I have to use based on the hole os? Or at least thats how I think the information is given, I haven’t read anywhere that its needs any access to anything else then the sandbox folder for this kinda information.
There is a PHP port for iOS, but it’s a standalone app that you write your PHP directly into. It can’t run like executing code from another app. It’s also $10 per install.
Apache Codova and Zend studios have built a way for PHP programmers to build native apps, but this would not be using Corona SDK, but their system.
If you want to use Corona SDK/Lua, I’m afraid the only option open to you now is Corona Enterprise or CoronaCards. We are working on the Marketplace to allow Enterprise developer’s to build and sell their own plugins. No ETA on it’s availability, but when it comes on line, you could commission an Enterprise developer to build a plugin that would fetch the various native bits of data you need.
Rob