Codeigniter running background scripts with same configuration and libraries - php

Fellows,
I want when I do a fileupload on codeigniter when upload finished to run a background process.
The background process will read the file and will insert data on my db. What I want is to the background script (that will be written in php) to be able to use codeignter's configuration and query builder. Because codeingiter's methods are more convenient than uusinhg vanila php.
I know to I can execute stuff on the background via exec and that's now what I am asking. I am asking how the executed script can use codeigniter's methods and libraries.

Check out the documentation on Running via the CLI. It may be possible to pass what they show as a terminal command as the argument to exec and achieve what you want.

Related

Calling C program with PHP

I’ve written a small database engine in C that works by reading commands you input in the console and it outputs the result.
Is there any way of me writting some PHP code that could send arguments to the console and recieve the output back to PHP without restarting the compiled program.
Is there a better way of doing this?
You say you want the PHP to send and receive messages to your program without restarting the compiled program.
So I don't think using shell_exec or proc_open will work how you want, since these commands both load a fresh instance of the compiled program.
Instead, I suggest you look into sockets, and how you would rewrite your database engine to use those instead of STDIN/STDOUT. Then you can use PHP's socket functions to communicate between your applications. And you'll have just one instance of your compiled program running in the background, even with multiple hits to your PHP script.

Passing js file from php to mongo

I have complex js file that do some heavy calculation and save result to collection.
This written in js because i wan't to avid data transmission.
currently i pass script to mongo shell in this way :
$mongodb < path_to_script
The script consists of several functions?
Is it possible to execute it from PHP?
I saw there is 'nolock' parameter that can be pass to evel method, is it possible to use it when executing from shell or from PHP?
What is consider more safe , using php execute wrapper or executing script from shell ?
When you run a .js file in the mongo shell, it's not running the javascript on the server; it's running it in the shell. Are you using server-side javascript features like db.eval and map/reduce in the mongo shell script?
Either way, I'd suggest forgoing the shell script and server-side javascript functions and either using the aggregation framework for server-side processing or implementing the logic in PHP application code. Server-side javascript has serious performance and security limitations and it's best to avoid using it when possible.
You can read the js file and execute it in PHP using execute which is a wrapper to the eval command. The nolock option can be added in the arguments.
$code = file_get_contents('filenam.js');
$db->execute($code, array('nolock' => true));
The php execute wrapper should be safer and better solution. If you execute js using shell in PHP, you will need to give permission to php to execute shell script using shell_exec(), which is impossible if you use hosting service and don't have admin right on the host.

how to get a php script to run a .cpp file

i am trying to find a way to have a PHP script execute a .cpp file, and then return the results via PHP.
I will map out my methodology to avoid confusion in my question:
Certain action on webpage (Button click) -> PHP runs .cpp file -> the results of the .cpp file are returned to PHP -> returned data is used to repopulate the page .
Is this possible to do? (please do not vote down, i have looked online and could not find a solid lead to help me establish this connection)
I hope you mean to run a built executable...
The exec function will run the application similar to running it through a command line. This means that you can get the standard output of the application like you would through the command line.
How to run abc.exe using php
It's kind of kludgy, if you can, just duplicate the executables functionality in PHP.

How do I run a php function in a subprocess in Symfony2?

I want to run some functions parallel in the background.
Is there a nice way to do this in Symfony2 or even with php?
Or is there only the Symfony\Component\Process\Process?
Can I use this Process with a function? I need the actual Context (logged in user and some session data), so it is not possible to source the function out to an external php-file...
Symfony2 Process component allows you to run some shell command or execute php-script in a different process.
To run exact function in a thread try look at PHP Thread class

Calling fcsh from PHP script

My question is whether or not Flex's fcsh can be called from within a PHP script. Here is the background:
I have been created a simple process that creates a simple quiz/tutorial by converting a text file into a .mxml file and compiling to a .swf file using the mxmlc compiler. This works well from the command line, but I wanted to make the process easier by creating a web-interface to do this. My initial attempts with PHP's exec() function have not worked. The Python scripts I use to create the .mxml file work fine (using exec()), but I have not been able to get the mxmlc compiler to work.
After searching on the Web and on this site, I believe that using fcsh (instead of mxmlc) may be the way to go. Using fcsh would certainly compile the .mxml file faster (after the first run), and I think that fcsh can be launched as a service that might be able to be called from PHP.
On the other hand, maybe I am approaching this the wrong way. Would it be better to write a Flex application that calls fcsh and avoid using PHP?
Edit: Using fcshctl as hasseg suggested in his answer below worked very well. Thanks Ali.
The problem with calling fcsh from within scripts is that it works as an interactive shell instead of taking command-line arguments, compiling, and returning an exit status. There are different ways to get around this, which I've listed in this blog post of mine, where I mainly talk about fcshctl (which is my own solution for this,) but at the bottom of the post I've also listed other similar solutions to get fcsh integrated into nonstandard build workflows.
There are a few other ways in php to execute an external script. They are exec(), passthru(), system(), and backticks i.e. the key to the left of the 1 key. Each one has a different purpose and return mechanism.
You may have to put the command that executes your executable into a script and call that script via one of these functions.
Is there a particular reason why you can't use mxmlc directly? It seems like it would be easier to call than fcsh. Just specify all your compiler options in a XML file run it like mxmlc -load-config path/to/config.xml. You can find an example of the XML configuration format in FLEX_HOME/frameworks/flex-config.xml.

Categories