Thursday, 26 November 2015

PHP and long running processes

PHP and long running processes

It seems this question keeps coming up on the PHP newsgroups and, now that I've plugged into Stack Overflow - I keep seeing it their too:

How I do I start a PHP program which takes a long time to complete and how do I track its progress?

While these tend to attract lots of replies, they are usually wrong.

The first thing to consider is that you need to seperate the the thing which takes a long time from its initiation, the ongoing monitoring and whatever final reporting is required.

Since we're talking about PHP its fair to assume that in most cases, the initiation will be a PHP script running in a webserver. However this is not a good place to keep a long-running program.

1) webservers are all about turning around requests quickly - indeed most have failsafe mechanisms to prevent one request hanging about too long.

2) the webserver ties the request to both the execution of the script and to the client socket connection. Typically NOT keeping a browser window open somewhere waiting for the job to complete is an objective for the exercise. Although the dependence on the client connection can be reduced via ignore_user_abort() that was never its intended purpose.

3) long-running typically means it will have quite different resource requirements than a typical web page script - e.g. lots of file handles being opened and closed, more memory being consumed.

Most commentators come back with the suggestion of spawning a seperate thread of execution, either using fork or via the shell. The former obviously does not solve the webserver related issues if the interpreter is running as a module - you're just going to fork the webserver process. You've not solved any of the web related issues and created a whole lot of new ones.

You need to create a new process certainly.

The obvious type of process to create would be a standalone PHP interpreter to process the long running job. So is there a standalone interpreter available to the webserver? The prospective implementor would need to check (and whether the webserver runs as chroot). So lets assume there is, our coder writes:

print shell_exec('/usr/bin/php -q longThing.php &');

A brave attempt. However they will soon find that this doesn't behave as well as they expected and keeps stopping. Why? because all the process they created runs concurrently with the php which created it, it is still a child of that process. Now this is where it starts to get complicated. In our example above, the webserver process finishes with the users script immediately after it creates the new process - however it will probably hang around waiting to be assigned a new request to deal with. However at some point the controller for the webserver processes will decide to terminate it - either as a matter of policy because it has dealt with a certain number of requests (for apache: MaxRequestsPerChild) or because it has too many idle processes (apache's MinSpareServers). However the webserver process should not stop until all its child processes have terminated. How this is dealt with varies by operating system and of course, webserver. Regardless, the coder has created a situation which should not have arisen.

But on a Unix system there are lots of jobs which run independently for long periods of time. They achieve this by:
1) they are first started, say as pid 1234, and try to fork, say to pid 1235 after calling fork, pid 1234 exits
2) pid 1235 will become the daemon - it closes all its open fds including those for stdin, stdout and stderr
3) pid 1235 now calls setsid(), this dissociates this process from the tree of processes which led to its creation (and 
typically makes it a child of the 'init' process).

You can do all this in a PHP script, assuming you've got the posix and pcntl extensions. However in my experience its usually a lot simpler to ask an existing daemon to run the script for you:

print `echo /usr/bin/php -q longThing.php | at now`;

But how do you get progress information? Simple, just get your long running script to report its progress to a file or a database, and use another, web-based script to read the progress / show the final result.

Troubleshooting (updated Sep 2014)

Following on from the feedback I've received, there's a couple of things to check if it doesn't go according to plan.

The atd has its own permissions system implemented via /etc/at.allow and /etc/at.deny - see you man pages for more info.

On Redhat machines, the apache uid is configured with shell /bin/nologin - this will silently discard any jobs submitted to it, hence a more complete solution is:

putenv("SHELL=/bin/bash");

print `echo /usr/bin/php -q longThing.php | at now 2>&1`;







Monday, 22 June 2015

10 Highest-Paying IT Security Jobs


According to a report issued by Burning Glass Technologies uncovers that employment postings over the IT security business have grown 74 percent somewhere around 2007 and 2013—double the rate of all other IT occupations. The Bureau of Labor Statistics is anticipating a 37 percent increment in Information Security Analyst positions alone somewhere around 2022.

With expanding concern around wholesale fraud, hacking, information security and protection, and with various prominent information breaks in the news, associations are multiplying down on their requirement for qualified, capable security experts. As anyone might expect, pay rates are expanding right along with demand.

Thus there is no doubt that the tech industry pays well. But the main question here is which job titles specifically make the most money in 2015 and which ones have tons of job openings? Here is a detailed list

1. CHIEF INFORMATION SECURITY OFFICER (CISO)

A CISO is a C-level administration official whose essential undertaking is to direct the general operations of an association’s IT security office and other related staff. The association’s general security is the preeminent concern of the CISO. CISOs make a middle compensation of $131,322, as indicated by PayScale’s 2015 evaluations

2. SECURITY ARCHITECT

A Security Architect is a senior-level worker who is in charge of building and keeping up the PC and system security base for an association. Security Architects make a middle compensation of $109,794. As indicated by PayScale, those on the lower end of the range make around $84,000, while the most generously compensated Security Architects win roughly $160,000.

3. SECURITY DIRECTOR

A Security Director is a senior-level representative whose assignment is to manage the usage of all IT efforts to establish safety all through an association. A Security Directors are in charge of outlining, overseeing and distributing assets to different security programs inside of an association’s security office; making client mindfulness and security agreeability instruction battles; collaborating with non-administration representatives; and offering key help to law in the case of a security investigation. Security Directors’ middle pay is variable, extending from $104,775 to $116,245. PayScale’s 2015 assessments find the pay range for Security Directors in the middle of $66,000 and $180,000.

4. SECURITY ADVISOR

Security Consultants work with customers to create methods for successful cyber security over their whole association. Notwithstanding knowing best practices and prescribed methods, they should likewise have strong correspondence, arrangement and venture administration abilities. Normal Salary: $198,909

5. DATA SECURITY OFFICER

This part is like that of the Chief Security Officer, yet concentrates all the more eagerly on ensuring an association’s information and protected innovation – the data related resources. CISO obligations normally incorporate keeping up best practices and outlining compelling arrangements to handle ruptures and different debacles. Normal Salary: $192,500.

6. DIGITAL SECURITY LEAD

A Cyber security Lead has an especially requesting and high-weight employment: assessing the association for potential vulnerabilities in conjunction with investigators and other security staff, identifying any assaults in progress and illuminating administration. Normal Salary: $175,000

7. LEAD SECURITY ENGINEERS

Lead Security Engineers can be tasked with numerous obligations, contingent upon their association: securing working situations, telephony and feature gathering frameworks and programming, equipment and data. Normal Salary: $174,375
8. COMPUTER FORENSICS EXPERT

A Computer Forensics Expert is in charge of breaking down proof assembled off of PCs, systems and other information stockpiling gadgets with an end goal to explore occurrences of cyber crime. These people ordinarily work mostly with law implementation organizations to incorporate proof for legitimate cases, draft specialized reports or offer master affirmation in trial. A mixture of associations, including law implementation, legitimate firms and all levels of government, are the most widely recognized businesses of Computer Forensics Experts. These Experts make a middle pay of $77,270. They can hope to procure at any rate $56,000, as indicated by the PayScale.

9. MALWARE ANALYST

A Malware Analyst is in charge of helping an association comprehend the infections, worms, bots, Trojans and different pernicious programming that debilitate its system consistently. Malware Analysts normally work with Computer Forensics Experts in the occasion of an interruption and/or suspicious PC conduct to help recognize vindictive projects that may have penetrated an association’s PC frameworks. Malware Analysts make a middle compensation of $75,000. They can hope to win in any event $48,000, however some can take home as much as $100,000 a year.

10. SECURITY SPECIALIST

A Security Specialist is a passage to mid-level worker who is in charge of finishing a mixed bag of obligations intended to reinforce the security of an association. Security Specialists are obliged to dissect the security necessities of an association’s frameworks, introduce and design security arrangements on corporate systems, perform helplessness testing and help train kindred representatives in security mindfulness. Security Specialists make a middle pay of $73,853. As per PayScale’s latest gauges, these people can hope to make in any event $43,000 yet can plan to take home as much as $113,000.


Tuesday, 16 June 2015

9 Must Read Articles For Programmers



We have long been talking about the ebooks that are must-read for designers and developers, but not much has been discussed about the articles that will make programmers learn a great deal. There are many developers/programmers that every now and then come up with the articles that focus on making their peer group learn and follow the easy steps to get the desired/aim at results.
So, for today we chose this topic to be talked about thereby helping you all with the websites where various useful articles have been published to help all your programmers out there the best way possible. I personally loved the topic of the day as I know it might be the best way out for many of you out there to learn miscellaneous things in a short span of time. Besides, if you are stuck somewhere, I guess checking these helpful articles written in simplest and easy understandable way will enlighten you by providing the best possible know-ho on the particular topic.
So, check must read programming articles and if you wish to go ahead reading them till the end, click on the link and go ahead. Also, do not forget to check out our other article featuring all the best free Machine Learning ebooks.

1. The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets

Written by Joel Spolsky founder of statckoverflow.com “The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)”  long back, this article promises to make developers learn smarter way. It easily makes them understand what is unicode, what is character encoding, how characters are represented using bytes and many more.

2. What should Every Programmer know about Security?

Security is a topic that ranges from encryption/decryption, SSL, web security, obfuscation, authentication, authorization and much more. If any of you programmer out there wants to learn the basic minimum knowledge, learn how to write exploit code, then this is the apt pick for you all. Without knowing how systems are exploited attaining knowledge about patching code is meaningless. Follow the secure Java coding practices provided by fortify, PMP and other static code analysis providers and learn everything about security.

3. What Every Web Developer must know about URL Encoding

Prepared by Stephane Epardaud, this write-up describes the common misconceptions about Uniform Resource Locator (URL) encoding. Also, it attempts to clarify URL encoding for HTTP, before presenting frequent problems and their solutions. One gets to learn the basics of URL grammar, general URL syntax in HTTP, other protocol and much more.

4. What Every Programmer Need to know about Game Networking

Ever wondered how multi-player games work sharing a consistent experience across the network? If yes, then his article would enlighten you with the possibilities programmers look for and work on. Its a must read for game programmers.

5. What Every Programmer should know about SEO

If you wish to know how search engines work then this is the article that you should definitely go about reading. The article provides all relevant information about basics of Search Engine Optimization in simple and easily understandable way.

6. What Every Programmer should know about Memory

Written back in 2007 this article is still a big hit for the fact that not all programmers have enough knowledge of memory which is important if you are into writing high performance application. Learn about RAM, CPU Caches, different types of memory, direct memory access, memory controller designs and Memory in general with this write-up.

7. 10 Things Every Java Programmer Should Know about String

String in Java is a important class, therefore it is of great importance to attain a good knowledge of different String functionalities. This article focuses on various important areas of String like string pool, string literal, comparing String using == vs equals(), converting bytes to String and everything you get to know to come up with the desired results.

8. Latency Numbers Every Programmer should know

This article makes programmers learn how to write a high performance application in any programming language e.g. Java or C++.

9. What Technical Details should a Programmer of a Web Application Consider before Making the Site Public

Going through this article will make programmers learn about various key technologies like HTTP, HTML, XML, CSS, JavaScript, browser compatibility, and ways of implementing the technical details of a web application consider before making the site public.
It is not always that one gets much time to check out ebooks and read them. The other best way to get useful information is by reading the articles that are dedicated to help all your programmers out there. If you have come up with any such helpful articles and wish to share with us, what’s the wait for then. Go ahead and leave your comments below.



Monday, 15 June 2015

3 tools that techies are using to boost productivity


The tech team, a.k.a., the people who are always one step ahead of you when it comes to new apps, sites, and extensions. Or, I should say, the people who were one step ahead of you. After you check out this article on tools that they're regularly using, you'll feel like an insider, too.

But, before you dig in, know these aren't just three random things that techies are currently utilizing. They're specifically designed to make automating and streamlining tasks a whole lot easier. And that means you can get more work done than ever!

I heard that groan. So I'll tell you what it also means: You'll have time to sneak out a little bit earlier a few nights this summer and enjoy some of this beautiful, beautiful sunshine.

1. Gmail Labs

If you're like many of us on this fine planet, you currently use Gmail to get through your day. But, I bet you didn't know that you can play mad scientist with it. And no, I'm not talking about creating a Frankenstein-like mash-up between your pharmacy spam and that weekly accounting report, I'm talking about Gmail Labs.

Gmail Labs are special settings that add helpful features to your email. You can get started by going into your account, clicking the gear icon, then "Settings," then a tab on the right called "Labs." There you'll find what you need to transform your email into a more manageable creature.

There are several to choose from, but I suggest starting with a few of my favorites.

Undo Send

How many times have you noticed you forgot to attach a file or worse, made a typo, just two seconds after clicking send? With Undo Send, you can stop that message from going out, saving yourself embarrassment and time spent sending along a follow-up email that says, "Now this time, with the attachment attached, lol."

Canned Responses

Do you find yourself answering the same emails over and over again? Save time (and your wrists) by not re-typing repetitive messages. Instead, build yourself a bank of standard responses that you can send out whenever needed.

Unread Message Icon

Sometimes you're waiting for an important email to come in, but for one reason or another, you don't have time to keep opening up your inbox. With the Unread Message Icon, you can just glance at your Gmail browser tab and quickly see when it hits your inbox.

2. IFTTT

IFTTT, short for "If This, Then That," is a simple, but surprisingly powerful, automation tool that combines your favorite online services. Once you sign up for a free account, you can start creating recipes. Or as I call it, magic!
And creating recipes is a breeze. Just choose the cause (the "if") and the result you want (the "that"). For example, I want to make sure that I remember to return any calls I miss while I'm in meetings. So, one of my IFTTT recipes is: If I miss a phone call, add it to my to-do list. That means I don't have to worry any more that I'll forget to check my missed calls — because there's a reminder ready and waiting for me in my task manager.

What else can you do with IFTTT? That's somewhat up to your imagination. It currently lets you connect a fantastic number of online services, from Gmail to Slack to DropBox to Evernote, plus dozens and dozens more.

3. Workflow or Llama

Just because you're at work doesn't mean you should forget your phone as an automation tool. In fact, automating tasks on your phone can be one of the best ways to make your work life easier, especially if you're often away from your desk.
Workflow is a relative newcomer for iOS that's knocking the socks off of iPhone users around the world. It lets you easily combine functions or apps on your phone in a certain order. Combining them makes it possible to do manual things automatically.
Clever Workflow actions that you can set up once, and then use over and over, include turning a web page into a PDF, sending a message with your arrival time based on your current location, or reading text aloud to you.



Jealous of iPhone owners right now? Don't be.
Llama for Android has been around for years, yet it's flown under the radar. It also lets you work some magic on your phone with just a little minor set-up. You can have your phone silenced whenever you have a meeting scheduled on your calendar, instantly connect to your office Wi-Fi when you get to work, or pop up a reminder to stand and stretch once an hour.


All of these tools are easy to use, and they really can make a big dent in your daily to-do list. So, stop wasting your time doing needless work, and start using these to get finished with your work faster.

ReadMore




Sunday, 14 June 2015

Is Facebook Going To Become The New Google


For close to two decades, Google has been the dominant online brand. It’s the name people turn to whenever they go to the web with a query. It provides maps, email, cloud storage, encyclopedic information entries, news, videos, operating systems, and countless other services—for free—to people around the world. Whether you judge it in terms of its technological sophistication, its authority and influence, its revenue-generating power, or just its scale, it is the preeminent force in the online world, and few companies can compete with it.


In terms of competitors, Bing and Yahoo are the only real brands that come to mind. Together, they account for less than a third of all search traffic, and most people don’t give them a second thought because they aren’t nearly as sophisticated as Google and don’t have access to anywhere near the amount of resources that Google does....Read More