WebApp session manipulation from console app

Is it possible from WebApplication to pass the Session variable to console application, so the console application can add some elements to the $_SESSION that can be accessed latter from the WebApplication?

I guess direct manipulation of the session storage file is hardly the best practice. :)

In order to get better grasp of the problem imagine the following scenario:

The WebUser start search on the web page. The search results are coming form 20 different sites and each site takes like 30 sec. to produce the results.

So instead of making the user wait for 20 x 30sec = 10min. in order to receive the results, my idea is the WebApplication to start simultaneously 20 console applications that each will fetch the results. This way the total time needed will be 30 sec.

Is there a way the results obtained from each of the console apps to be injected into the session structure of the WebApplication?

This way I hope to avoid some middle layer storage dependencies, like database, filesystem …

What you think is the best practice in this case?

you shouldn’t alter users session from outside webapp… it is rather security issue.

I would use cache system instead (you can share cacheid-s and cache storage between webapp and consoleapp) or tool like gearmand (php interface: http://php.net/manual/en/book.gearman.php, there is also some Yii extension for gearmand) which allows you to async execute tasks (on defined pool of runners so you can control total number of working php processes) and then gather results from it when they are ready…

Thank you @redguy!

I was afraid, that some process control and queuing framework will be needed … ehhh … nothing is ever simple.

Is there any reason why gearmand should be used?

Can I replace it with some of the Node.js process control packages?

This one looks nice enough: http://learnboost.github.io/kue

The project is developed by multiple developers and I will have really hard time explaining to them how to install and run gearmand … as I know some of them maybe I will get old before they manage to start it on their development Windows machines. :)

it is only one proposal. we are using it with success and can be seamlessly integrated in php application.

I started evaluating pthreads extension: http://php.net/manual/en/book.pthreads.php by Joe Watkins

It looks like this way we can make better utilization of the memory and hopefully even distribution of the load between the CPU existing cores.

Also there is no problems running on Windows OS and no need for external daemons like gearmand.

Sounds like win-win to me, so I started worrying what is the catch here? :)

Is there anybody with hands on experience with pthreads? Your comments will be highly appreciated!

Isn’t gearmand used for delayed processing? Never used it though so I may be wrong (only have experience with beanstalkd)

Have you tried using multi curl? Sounds like you want to access 20 different things at the same time right after clicking a search button

Thank you for the replay @georaldc!

I have used multi curl with great success, but in this case it is not a good match I think.

If only the APIs were RESTful, then multi-curl will be the best option, but … no such luck.

The so called "search results" are obtained via series of SOAP calls to different providers.

Those calls open sessions and they also had intermediate state.

Ideally I will like to be able to check and report the current state for each of the 20 APIs.

gearman is a dispatcher of tasks to defined runners. You can use it synchronously or asynchronously. Tasks are of course queued… so it has many applications